xref: /minix3/minix/drivers/power/acpi/utilities/utobject.c (revision 29492bb71c7148a089a5afafa0c99409161218df)
1433d6423SLionel Sambuc /******************************************************************************
2433d6423SLionel Sambuc  *
3433d6423SLionel Sambuc  * Module Name: utobject - ACPI object create/delete/size/cache routines
4433d6423SLionel Sambuc  *
5433d6423SLionel Sambuc  *****************************************************************************/
6433d6423SLionel Sambuc 
7*29492bb7SDavid van Moolenbroek /*
8*29492bb7SDavid van Moolenbroek  * Copyright (C) 2000 - 2014, Intel Corp.
9433d6423SLionel Sambuc  * All rights reserved.
10433d6423SLionel Sambuc  *
11*29492bb7SDavid van Moolenbroek  * Redistribution and use in source and binary forms, with or without
12*29492bb7SDavid van Moolenbroek  * modification, are permitted provided that the following conditions
13*29492bb7SDavid van Moolenbroek  * are met:
14*29492bb7SDavid van Moolenbroek  * 1. Redistributions of source code must retain the above copyright
15*29492bb7SDavid van Moolenbroek  *    notice, this list of conditions, and the following disclaimer,
16*29492bb7SDavid van Moolenbroek  *    without modification.
17*29492bb7SDavid van Moolenbroek  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18*29492bb7SDavid van Moolenbroek  *    substantially similar to the "NO WARRANTY" disclaimer below
19*29492bb7SDavid van Moolenbroek  *    ("Disclaimer") and any redistribution must be conditioned upon
20*29492bb7SDavid van Moolenbroek  *    including a substantially similar Disclaimer requirement for further
21*29492bb7SDavid van Moolenbroek  *    binary redistribution.
22*29492bb7SDavid van Moolenbroek  * 3. Neither the names of the above-listed copyright holders nor the names
23*29492bb7SDavid van Moolenbroek  *    of any contributors may be used to endorse or promote products derived
24*29492bb7SDavid van Moolenbroek  *    from this software without specific prior written permission.
25433d6423SLionel Sambuc  *
26*29492bb7SDavid van Moolenbroek  * Alternatively, this software may be distributed under the terms of the
27*29492bb7SDavid van Moolenbroek  * GNU General Public License ("GPL") version 2 as published by the Free
28*29492bb7SDavid van Moolenbroek  * Software Foundation.
29433d6423SLionel Sambuc  *
30*29492bb7SDavid van Moolenbroek  * NO WARRANTY
31*29492bb7SDavid van Moolenbroek  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32*29492bb7SDavid van Moolenbroek  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33*29492bb7SDavid van Moolenbroek  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34*29492bb7SDavid van Moolenbroek  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35*29492bb7SDavid van Moolenbroek  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36*29492bb7SDavid van Moolenbroek  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37*29492bb7SDavid van Moolenbroek  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38*29492bb7SDavid van Moolenbroek  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39*29492bb7SDavid van Moolenbroek  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40*29492bb7SDavid van Moolenbroek  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41*29492bb7SDavid van Moolenbroek  * POSSIBILITY OF SUCH DAMAGES.
42*29492bb7SDavid van Moolenbroek  */
43433d6423SLionel Sambuc 
44433d6423SLionel Sambuc #include "acpi.h"
45433d6423SLionel Sambuc #include "accommon.h"
46433d6423SLionel Sambuc #include "acnamesp.h"
47433d6423SLionel Sambuc 
48433d6423SLionel Sambuc 
49433d6423SLionel Sambuc #define _COMPONENT          ACPI_UTILITIES
50433d6423SLionel Sambuc         ACPI_MODULE_NAME    ("utobject")
51433d6423SLionel Sambuc 
52433d6423SLionel Sambuc /* Local prototypes */
53433d6423SLionel Sambuc 
54433d6423SLionel Sambuc static ACPI_STATUS
55433d6423SLionel Sambuc AcpiUtGetSimpleObjectSize (
56433d6423SLionel Sambuc     ACPI_OPERAND_OBJECT     *Obj,
57433d6423SLionel Sambuc     ACPI_SIZE               *ObjLength);
58433d6423SLionel Sambuc 
59433d6423SLionel Sambuc static ACPI_STATUS
60433d6423SLionel Sambuc AcpiUtGetPackageObjectSize (
61433d6423SLionel Sambuc     ACPI_OPERAND_OBJECT     *Obj,
62433d6423SLionel Sambuc     ACPI_SIZE               *ObjLength);
63433d6423SLionel Sambuc 
64433d6423SLionel Sambuc static ACPI_STATUS
65433d6423SLionel Sambuc AcpiUtGetElementLength (
66433d6423SLionel Sambuc     UINT8                   ObjectType,
67433d6423SLionel Sambuc     ACPI_OPERAND_OBJECT     *SourceObject,
68433d6423SLionel Sambuc     ACPI_GENERIC_STATE      *State,
69433d6423SLionel Sambuc     void                    *Context);
70433d6423SLionel Sambuc 
71433d6423SLionel Sambuc 
72433d6423SLionel Sambuc /*******************************************************************************
73433d6423SLionel Sambuc  *
74433d6423SLionel Sambuc  * FUNCTION:    AcpiUtCreateInternalObjectDbg
75433d6423SLionel Sambuc  *
76433d6423SLionel Sambuc  * PARAMETERS:  ModuleName          - Source file name of caller
77433d6423SLionel Sambuc  *              LineNumber          - Line number of caller
78433d6423SLionel Sambuc  *              ComponentId         - Component type of caller
79433d6423SLionel Sambuc  *              Type                - ACPI Type of the new object
80433d6423SLionel Sambuc  *
81433d6423SLionel Sambuc  * RETURN:      A new internal object, null on failure
82433d6423SLionel Sambuc  *
83433d6423SLionel Sambuc  * DESCRIPTION: Create and initialize a new internal object.
84433d6423SLionel Sambuc  *
85433d6423SLionel Sambuc  * NOTE:        We always allocate the worst-case object descriptor because
86433d6423SLionel Sambuc  *              these objects are cached, and we want them to be
87433d6423SLionel Sambuc  *              one-size-satisifies-any-request. This in itself may not be
88433d6423SLionel Sambuc  *              the most memory efficient, but the efficiency of the object
89433d6423SLionel Sambuc  *              cache should more than make up for this!
90433d6423SLionel Sambuc  *
91433d6423SLionel Sambuc  ******************************************************************************/
92433d6423SLionel Sambuc 
93433d6423SLionel Sambuc ACPI_OPERAND_OBJECT  *
AcpiUtCreateInternalObjectDbg(const char * ModuleName,UINT32 LineNumber,UINT32 ComponentId,ACPI_OBJECT_TYPE Type)94433d6423SLionel Sambuc AcpiUtCreateInternalObjectDbg (
95433d6423SLionel Sambuc     const char              *ModuleName,
96433d6423SLionel Sambuc     UINT32                  LineNumber,
97433d6423SLionel Sambuc     UINT32                  ComponentId,
98433d6423SLionel Sambuc     ACPI_OBJECT_TYPE        Type)
99433d6423SLionel Sambuc {
100433d6423SLionel Sambuc     ACPI_OPERAND_OBJECT     *Object;
101433d6423SLionel Sambuc     ACPI_OPERAND_OBJECT     *SecondObject;
102433d6423SLionel Sambuc 
103433d6423SLionel Sambuc 
104433d6423SLionel Sambuc     ACPI_FUNCTION_TRACE_STR (UtCreateInternalObjectDbg,
105433d6423SLionel Sambuc         AcpiUtGetTypeName (Type));
106433d6423SLionel Sambuc 
107433d6423SLionel Sambuc 
108433d6423SLionel Sambuc     /* Allocate the raw object descriptor */
109433d6423SLionel Sambuc 
110433d6423SLionel Sambuc     Object = AcpiUtAllocateObjectDescDbg (ModuleName, LineNumber, ComponentId);
111433d6423SLionel Sambuc     if (!Object)
112433d6423SLionel Sambuc     {
113433d6423SLionel Sambuc         return_PTR (NULL);
114433d6423SLionel Sambuc     }
115433d6423SLionel Sambuc 
116433d6423SLionel Sambuc     switch (Type)
117433d6423SLionel Sambuc     {
118433d6423SLionel Sambuc     case ACPI_TYPE_REGION:
119433d6423SLionel Sambuc     case ACPI_TYPE_BUFFER_FIELD:
120433d6423SLionel Sambuc     case ACPI_TYPE_LOCAL_BANK_FIELD:
121433d6423SLionel Sambuc 
122433d6423SLionel Sambuc         /* These types require a secondary object */
123433d6423SLionel Sambuc 
124433d6423SLionel Sambuc         SecondObject = AcpiUtAllocateObjectDescDbg (ModuleName,
125433d6423SLionel Sambuc                             LineNumber, ComponentId);
126433d6423SLionel Sambuc         if (!SecondObject)
127433d6423SLionel Sambuc         {
128433d6423SLionel Sambuc             AcpiUtDeleteObjectDesc (Object);
129433d6423SLionel Sambuc             return_PTR (NULL);
130433d6423SLionel Sambuc         }
131433d6423SLionel Sambuc 
132433d6423SLionel Sambuc         SecondObject->Common.Type = ACPI_TYPE_LOCAL_EXTRA;
133433d6423SLionel Sambuc         SecondObject->Common.ReferenceCount = 1;
134433d6423SLionel Sambuc 
135433d6423SLionel Sambuc         /* Link the second object to the first */
136433d6423SLionel Sambuc 
137433d6423SLionel Sambuc         Object->Common.NextObject = SecondObject;
138433d6423SLionel Sambuc         break;
139433d6423SLionel Sambuc 
140433d6423SLionel Sambuc     default:
141*29492bb7SDavid van Moolenbroek 
142433d6423SLionel Sambuc         /* All others have no secondary object */
143433d6423SLionel Sambuc         break;
144433d6423SLionel Sambuc     }
145433d6423SLionel Sambuc 
146433d6423SLionel Sambuc     /* Save the object type in the object descriptor */
147433d6423SLionel Sambuc 
148433d6423SLionel Sambuc     Object->Common.Type = (UINT8) Type;
149433d6423SLionel Sambuc 
150433d6423SLionel Sambuc     /* Init the reference count */
151433d6423SLionel Sambuc 
152433d6423SLionel Sambuc     Object->Common.ReferenceCount = 1;
153433d6423SLionel Sambuc 
154433d6423SLionel Sambuc     /* Any per-type initialization should go here */
155433d6423SLionel Sambuc 
156433d6423SLionel Sambuc     return_PTR (Object);
157433d6423SLionel Sambuc }
158433d6423SLionel Sambuc 
159433d6423SLionel Sambuc 
160433d6423SLionel Sambuc /*******************************************************************************
161433d6423SLionel Sambuc  *
162433d6423SLionel Sambuc  * FUNCTION:    AcpiUtCreatePackageObject
163433d6423SLionel Sambuc  *
164433d6423SLionel Sambuc  * PARAMETERS:  Count               - Number of package elements
165433d6423SLionel Sambuc  *
166433d6423SLionel Sambuc  * RETURN:      Pointer to a new Package object, null on failure
167433d6423SLionel Sambuc  *
168433d6423SLionel Sambuc  * DESCRIPTION: Create a fully initialized package object
169433d6423SLionel Sambuc  *
170433d6423SLionel Sambuc  ******************************************************************************/
171433d6423SLionel Sambuc 
172433d6423SLionel Sambuc ACPI_OPERAND_OBJECT *
AcpiUtCreatePackageObject(UINT32 Count)173433d6423SLionel Sambuc AcpiUtCreatePackageObject (
174433d6423SLionel Sambuc     UINT32                  Count)
175433d6423SLionel Sambuc {
176433d6423SLionel Sambuc     ACPI_OPERAND_OBJECT     *PackageDesc;
177433d6423SLionel Sambuc     ACPI_OPERAND_OBJECT     **PackageElements;
178433d6423SLionel Sambuc 
179433d6423SLionel Sambuc 
180433d6423SLionel Sambuc     ACPI_FUNCTION_TRACE_U32 (UtCreatePackageObject, Count);
181433d6423SLionel Sambuc 
182433d6423SLionel Sambuc 
183433d6423SLionel Sambuc     /* Create a new Package object */
184433d6423SLionel Sambuc 
185433d6423SLionel Sambuc     PackageDesc = AcpiUtCreateInternalObject (ACPI_TYPE_PACKAGE);
186433d6423SLionel Sambuc     if (!PackageDesc)
187433d6423SLionel Sambuc     {
188433d6423SLionel Sambuc         return_PTR (NULL);
189433d6423SLionel Sambuc     }
190433d6423SLionel Sambuc 
191433d6423SLionel Sambuc     /*
192433d6423SLionel Sambuc      * Create the element array. Count+1 allows the array to be null
193433d6423SLionel Sambuc      * terminated.
194433d6423SLionel Sambuc      */
195433d6423SLionel Sambuc     PackageElements = ACPI_ALLOCATE_ZEROED (
196433d6423SLionel Sambuc                         ((ACPI_SIZE) Count + 1) * sizeof (void *));
197433d6423SLionel Sambuc     if (!PackageElements)
198433d6423SLionel Sambuc     {
199433d6423SLionel Sambuc         ACPI_FREE (PackageDesc);
200433d6423SLionel Sambuc         return_PTR (NULL);
201433d6423SLionel Sambuc     }
202433d6423SLionel Sambuc 
203433d6423SLionel Sambuc     PackageDesc->Package.Count = Count;
204433d6423SLionel Sambuc     PackageDesc->Package.Elements = PackageElements;
205433d6423SLionel Sambuc     return_PTR (PackageDesc);
206433d6423SLionel Sambuc }
207433d6423SLionel Sambuc 
208433d6423SLionel Sambuc 
209433d6423SLionel Sambuc /*******************************************************************************
210433d6423SLionel Sambuc  *
211433d6423SLionel Sambuc  * FUNCTION:    AcpiUtCreateIntegerObject
212433d6423SLionel Sambuc  *
213433d6423SLionel Sambuc  * PARAMETERS:  InitialValue        - Initial value for the integer
214433d6423SLionel Sambuc  *
215433d6423SLionel Sambuc  * RETURN:      Pointer to a new Integer object, null on failure
216433d6423SLionel Sambuc  *
217433d6423SLionel Sambuc  * DESCRIPTION: Create an initialized integer object
218433d6423SLionel Sambuc  *
219433d6423SLionel Sambuc  ******************************************************************************/
220433d6423SLionel Sambuc 
221433d6423SLionel Sambuc ACPI_OPERAND_OBJECT *
AcpiUtCreateIntegerObject(UINT64 InitialValue)222433d6423SLionel Sambuc AcpiUtCreateIntegerObject (
223433d6423SLionel Sambuc     UINT64                  InitialValue)
224433d6423SLionel Sambuc {
225433d6423SLionel Sambuc     ACPI_OPERAND_OBJECT     *IntegerDesc;
226433d6423SLionel Sambuc 
227433d6423SLionel Sambuc 
228433d6423SLionel Sambuc     ACPI_FUNCTION_TRACE (UtCreateIntegerObject);
229433d6423SLionel Sambuc 
230433d6423SLionel Sambuc 
231433d6423SLionel Sambuc     /* Create and initialize a new integer object */
232433d6423SLionel Sambuc 
233433d6423SLionel Sambuc     IntegerDesc = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
234433d6423SLionel Sambuc     if (!IntegerDesc)
235433d6423SLionel Sambuc     {
236433d6423SLionel Sambuc         return_PTR (NULL);
237433d6423SLionel Sambuc     }
238433d6423SLionel Sambuc 
239433d6423SLionel Sambuc     IntegerDesc->Integer.Value = InitialValue;
240433d6423SLionel Sambuc     return_PTR (IntegerDesc);
241433d6423SLionel Sambuc }
242433d6423SLionel Sambuc 
243433d6423SLionel Sambuc 
244433d6423SLionel Sambuc /*******************************************************************************
245433d6423SLionel Sambuc  *
246433d6423SLionel Sambuc  * FUNCTION:    AcpiUtCreateBufferObject
247433d6423SLionel Sambuc  *
248433d6423SLionel Sambuc  * PARAMETERS:  BufferSize             - Size of buffer to be created
249433d6423SLionel Sambuc  *
250433d6423SLionel Sambuc  * RETURN:      Pointer to a new Buffer object, null on failure
251433d6423SLionel Sambuc  *
252433d6423SLionel Sambuc  * DESCRIPTION: Create a fully initialized buffer object
253433d6423SLionel Sambuc  *
254433d6423SLionel Sambuc  ******************************************************************************/
255433d6423SLionel Sambuc 
256433d6423SLionel Sambuc ACPI_OPERAND_OBJECT *
AcpiUtCreateBufferObject(ACPI_SIZE BufferSize)257433d6423SLionel Sambuc AcpiUtCreateBufferObject (
258433d6423SLionel Sambuc     ACPI_SIZE               BufferSize)
259433d6423SLionel Sambuc {
260433d6423SLionel Sambuc     ACPI_OPERAND_OBJECT     *BufferDesc;
261433d6423SLionel Sambuc     UINT8                   *Buffer = NULL;
262433d6423SLionel Sambuc 
263433d6423SLionel Sambuc 
264433d6423SLionel Sambuc     ACPI_FUNCTION_TRACE_U32 (UtCreateBufferObject, BufferSize);
265433d6423SLionel Sambuc 
266433d6423SLionel Sambuc 
267433d6423SLionel Sambuc     /* Create a new Buffer object */
268433d6423SLionel Sambuc 
269433d6423SLionel Sambuc     BufferDesc = AcpiUtCreateInternalObject (ACPI_TYPE_BUFFER);
270433d6423SLionel Sambuc     if (!BufferDesc)
271433d6423SLionel Sambuc     {
272433d6423SLionel Sambuc         return_PTR (NULL);
273433d6423SLionel Sambuc     }
274433d6423SLionel Sambuc 
275433d6423SLionel Sambuc     /* Create an actual buffer only if size > 0 */
276433d6423SLionel Sambuc 
277433d6423SLionel Sambuc     if (BufferSize > 0)
278433d6423SLionel Sambuc     {
279433d6423SLionel Sambuc         /* Allocate the actual buffer */
280433d6423SLionel Sambuc 
281433d6423SLionel Sambuc         Buffer = ACPI_ALLOCATE_ZEROED (BufferSize);
282433d6423SLionel Sambuc         if (!Buffer)
283433d6423SLionel Sambuc         {
284433d6423SLionel Sambuc             ACPI_ERROR ((AE_INFO, "Could not allocate size %u",
285433d6423SLionel Sambuc                 (UINT32) BufferSize));
286433d6423SLionel Sambuc             AcpiUtRemoveReference (BufferDesc);
287433d6423SLionel Sambuc             return_PTR (NULL);
288433d6423SLionel Sambuc         }
289433d6423SLionel Sambuc     }
290433d6423SLionel Sambuc 
291433d6423SLionel Sambuc     /* Complete buffer object initialization */
292433d6423SLionel Sambuc 
293433d6423SLionel Sambuc     BufferDesc->Buffer.Flags |= AOPOBJ_DATA_VALID;
294433d6423SLionel Sambuc     BufferDesc->Buffer.Pointer = Buffer;
295433d6423SLionel Sambuc     BufferDesc->Buffer.Length = (UINT32) BufferSize;
296433d6423SLionel Sambuc 
297433d6423SLionel Sambuc     /* Return the new buffer descriptor */
298433d6423SLionel Sambuc 
299433d6423SLionel Sambuc     return_PTR (BufferDesc);
300433d6423SLionel Sambuc }
301433d6423SLionel Sambuc 
302433d6423SLionel Sambuc 
303433d6423SLionel Sambuc /*******************************************************************************
304433d6423SLionel Sambuc  *
305433d6423SLionel Sambuc  * FUNCTION:    AcpiUtCreateStringObject
306433d6423SLionel Sambuc  *
307433d6423SLionel Sambuc  * PARAMETERS:  StringSize          - Size of string to be created. Does not
308433d6423SLionel Sambuc  *                                    include NULL terminator, this is added
309433d6423SLionel Sambuc  *                                    automatically.
310433d6423SLionel Sambuc  *
311433d6423SLionel Sambuc  * RETURN:      Pointer to a new String object
312433d6423SLionel Sambuc  *
313433d6423SLionel Sambuc  * DESCRIPTION: Create a fully initialized string object
314433d6423SLionel Sambuc  *
315433d6423SLionel Sambuc  ******************************************************************************/
316433d6423SLionel Sambuc 
317433d6423SLionel Sambuc ACPI_OPERAND_OBJECT *
AcpiUtCreateStringObject(ACPI_SIZE StringSize)318433d6423SLionel Sambuc AcpiUtCreateStringObject (
319433d6423SLionel Sambuc     ACPI_SIZE               StringSize)
320433d6423SLionel Sambuc {
321433d6423SLionel Sambuc     ACPI_OPERAND_OBJECT     *StringDesc;
322433d6423SLionel Sambuc     char                    *String;
323433d6423SLionel Sambuc 
324433d6423SLionel Sambuc 
325433d6423SLionel Sambuc     ACPI_FUNCTION_TRACE_U32 (UtCreateStringObject, StringSize);
326433d6423SLionel Sambuc 
327433d6423SLionel Sambuc 
328433d6423SLionel Sambuc     /* Create a new String object */
329433d6423SLionel Sambuc 
330433d6423SLionel Sambuc     StringDesc = AcpiUtCreateInternalObject (ACPI_TYPE_STRING);
331433d6423SLionel Sambuc     if (!StringDesc)
332433d6423SLionel Sambuc     {
333433d6423SLionel Sambuc         return_PTR (NULL);
334433d6423SLionel Sambuc     }
335433d6423SLionel Sambuc 
336433d6423SLionel Sambuc     /*
337433d6423SLionel Sambuc      * Allocate the actual string buffer -- (Size + 1) for NULL terminator.
338433d6423SLionel Sambuc      * NOTE: Zero-length strings are NULL terminated
339433d6423SLionel Sambuc      */
340433d6423SLionel Sambuc     String = ACPI_ALLOCATE_ZEROED (StringSize + 1);
341433d6423SLionel Sambuc     if (!String)
342433d6423SLionel Sambuc     {
343433d6423SLionel Sambuc         ACPI_ERROR ((AE_INFO, "Could not allocate size %u",
344433d6423SLionel Sambuc             (UINT32) StringSize));
345433d6423SLionel Sambuc         AcpiUtRemoveReference (StringDesc);
346433d6423SLionel Sambuc         return_PTR (NULL);
347433d6423SLionel Sambuc     }
348433d6423SLionel Sambuc 
349433d6423SLionel Sambuc     /* Complete string object initialization */
350433d6423SLionel Sambuc 
351433d6423SLionel Sambuc     StringDesc->String.Pointer = String;
352433d6423SLionel Sambuc     StringDesc->String.Length = (UINT32) StringSize;
353433d6423SLionel Sambuc 
354433d6423SLionel Sambuc     /* Return the new string descriptor */
355433d6423SLionel Sambuc 
356433d6423SLionel Sambuc     return_PTR (StringDesc);
357433d6423SLionel Sambuc }
358433d6423SLionel Sambuc 
359433d6423SLionel Sambuc 
360433d6423SLionel Sambuc /*******************************************************************************
361433d6423SLionel Sambuc  *
362433d6423SLionel Sambuc  * FUNCTION:    AcpiUtValidInternalObject
363433d6423SLionel Sambuc  *
364433d6423SLionel Sambuc  * PARAMETERS:  Object              - Object to be validated
365433d6423SLionel Sambuc  *
366433d6423SLionel Sambuc  * RETURN:      TRUE if object is valid, FALSE otherwise
367433d6423SLionel Sambuc  *
368*29492bb7SDavid van Moolenbroek  * DESCRIPTION: Validate a pointer to be of type ACPI_OPERAND_OBJECT
369433d6423SLionel Sambuc  *
370433d6423SLionel Sambuc  ******************************************************************************/
371433d6423SLionel Sambuc 
372433d6423SLionel Sambuc BOOLEAN
AcpiUtValidInternalObject(void * Object)373433d6423SLionel Sambuc AcpiUtValidInternalObject (
374433d6423SLionel Sambuc     void                    *Object)
375433d6423SLionel Sambuc {
376433d6423SLionel Sambuc 
377433d6423SLionel Sambuc     ACPI_FUNCTION_NAME (UtValidInternalObject);
378433d6423SLionel Sambuc 
379433d6423SLionel Sambuc 
380433d6423SLionel Sambuc     /* Check for a null pointer */
381433d6423SLionel Sambuc 
382433d6423SLionel Sambuc     if (!Object)
383433d6423SLionel Sambuc     {
384433d6423SLionel Sambuc         ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "**** Null Object Ptr\n"));
385433d6423SLionel Sambuc         return (FALSE);
386433d6423SLionel Sambuc     }
387433d6423SLionel Sambuc 
388433d6423SLionel Sambuc     /* Check the descriptor type field */
389433d6423SLionel Sambuc 
390433d6423SLionel Sambuc     switch (ACPI_GET_DESCRIPTOR_TYPE (Object))
391433d6423SLionel Sambuc     {
392433d6423SLionel Sambuc     case ACPI_DESC_TYPE_OPERAND:
393433d6423SLionel Sambuc 
394433d6423SLionel Sambuc         /* The object appears to be a valid ACPI_OPERAND_OBJECT */
395433d6423SLionel Sambuc 
396433d6423SLionel Sambuc         return (TRUE);
397433d6423SLionel Sambuc 
398433d6423SLionel Sambuc     default:
399*29492bb7SDavid van Moolenbroek 
400433d6423SLionel Sambuc         ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
401*29492bb7SDavid van Moolenbroek                 "%p is not an ACPI operand obj [%s]\n",
402433d6423SLionel Sambuc                 Object, AcpiUtGetDescriptorName (Object)));
403433d6423SLionel Sambuc         break;
404433d6423SLionel Sambuc     }
405433d6423SLionel Sambuc 
406433d6423SLionel Sambuc     return (FALSE);
407433d6423SLionel Sambuc }
408433d6423SLionel Sambuc 
409433d6423SLionel Sambuc 
410433d6423SLionel Sambuc /*******************************************************************************
411433d6423SLionel Sambuc  *
412433d6423SLionel Sambuc  * FUNCTION:    AcpiUtAllocateObjectDescDbg
413433d6423SLionel Sambuc  *
414433d6423SLionel Sambuc  * PARAMETERS:  ModuleName          - Caller's module name (for error output)
415433d6423SLionel Sambuc  *              LineNumber          - Caller's line number (for error output)
416433d6423SLionel Sambuc  *              ComponentId         - Caller's component ID (for error output)
417433d6423SLionel Sambuc  *
418433d6423SLionel Sambuc  * RETURN:      Pointer to newly allocated object descriptor. Null on error
419433d6423SLionel Sambuc  *
420433d6423SLionel Sambuc  * DESCRIPTION: Allocate a new object descriptor. Gracefully handle
421433d6423SLionel Sambuc  *              error conditions.
422433d6423SLionel Sambuc  *
423433d6423SLionel Sambuc  ******************************************************************************/
424433d6423SLionel Sambuc 
425433d6423SLionel Sambuc void *
AcpiUtAllocateObjectDescDbg(const char * ModuleName,UINT32 LineNumber,UINT32 ComponentId)426433d6423SLionel Sambuc AcpiUtAllocateObjectDescDbg (
427433d6423SLionel Sambuc     const char              *ModuleName,
428433d6423SLionel Sambuc     UINT32                  LineNumber,
429433d6423SLionel Sambuc     UINT32                  ComponentId)
430433d6423SLionel Sambuc {
431433d6423SLionel Sambuc     ACPI_OPERAND_OBJECT     *Object;
432433d6423SLionel Sambuc 
433433d6423SLionel Sambuc 
434433d6423SLionel Sambuc     ACPI_FUNCTION_TRACE (UtAllocateObjectDescDbg);
435433d6423SLionel Sambuc 
436433d6423SLionel Sambuc 
437433d6423SLionel Sambuc     Object = AcpiOsAcquireObject (AcpiGbl_OperandCache);
438433d6423SLionel Sambuc     if (!Object)
439433d6423SLionel Sambuc     {
440433d6423SLionel Sambuc         ACPI_ERROR ((ModuleName, LineNumber,
441433d6423SLionel Sambuc             "Could not allocate an object descriptor"));
442433d6423SLionel Sambuc 
443433d6423SLionel Sambuc         return_PTR (NULL);
444433d6423SLionel Sambuc     }
445433d6423SLionel Sambuc 
446433d6423SLionel Sambuc     /* Mark the descriptor type */
447433d6423SLionel Sambuc 
448433d6423SLionel Sambuc     ACPI_SET_DESCRIPTOR_TYPE (Object, ACPI_DESC_TYPE_OPERAND);
449433d6423SLionel Sambuc 
450433d6423SLionel Sambuc     ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "%p Size %X\n",
451433d6423SLionel Sambuc             Object, (UINT32) sizeof (ACPI_OPERAND_OBJECT)));
452433d6423SLionel Sambuc 
453433d6423SLionel Sambuc     return_PTR (Object);
454433d6423SLionel Sambuc }
455433d6423SLionel Sambuc 
456433d6423SLionel Sambuc 
457433d6423SLionel Sambuc /*******************************************************************************
458433d6423SLionel Sambuc  *
459433d6423SLionel Sambuc  * FUNCTION:    AcpiUtDeleteObjectDesc
460433d6423SLionel Sambuc  *
461433d6423SLionel Sambuc  * PARAMETERS:  Object          - An Acpi internal object to be deleted
462433d6423SLionel Sambuc  *
463433d6423SLionel Sambuc  * RETURN:      None.
464433d6423SLionel Sambuc  *
465433d6423SLionel Sambuc  * DESCRIPTION: Free an ACPI object descriptor or add it to the object cache
466433d6423SLionel Sambuc  *
467433d6423SLionel Sambuc  ******************************************************************************/
468433d6423SLionel Sambuc 
469433d6423SLionel Sambuc void
AcpiUtDeleteObjectDesc(ACPI_OPERAND_OBJECT * Object)470433d6423SLionel Sambuc AcpiUtDeleteObjectDesc (
471433d6423SLionel Sambuc     ACPI_OPERAND_OBJECT     *Object)
472433d6423SLionel Sambuc {
473433d6423SLionel Sambuc     ACPI_FUNCTION_TRACE_PTR (UtDeleteObjectDesc, Object);
474433d6423SLionel Sambuc 
475433d6423SLionel Sambuc 
476*29492bb7SDavid van Moolenbroek     /* Object must be of type ACPI_OPERAND_OBJECT */
477433d6423SLionel Sambuc 
478433d6423SLionel Sambuc     if (ACPI_GET_DESCRIPTOR_TYPE (Object) != ACPI_DESC_TYPE_OPERAND)
479433d6423SLionel Sambuc     {
480433d6423SLionel Sambuc         ACPI_ERROR ((AE_INFO,
481433d6423SLionel Sambuc             "%p is not an ACPI Operand object [%s]", Object,
482433d6423SLionel Sambuc             AcpiUtGetDescriptorName (Object)));
483433d6423SLionel Sambuc         return_VOID;
484433d6423SLionel Sambuc     }
485433d6423SLionel Sambuc 
486433d6423SLionel Sambuc     (void) AcpiOsReleaseObject (AcpiGbl_OperandCache, Object);
487433d6423SLionel Sambuc     return_VOID;
488433d6423SLionel Sambuc }
489433d6423SLionel Sambuc 
490433d6423SLionel Sambuc 
491433d6423SLionel Sambuc /*******************************************************************************
492433d6423SLionel Sambuc  *
493433d6423SLionel Sambuc  * FUNCTION:    AcpiUtGetSimpleObjectSize
494433d6423SLionel Sambuc  *
495433d6423SLionel Sambuc  * PARAMETERS:  InternalObject     - An ACPI operand object
496433d6423SLionel Sambuc  *              ObjLength          - Where the length is returned
497433d6423SLionel Sambuc  *
498433d6423SLionel Sambuc  * RETURN:      Status
499433d6423SLionel Sambuc  *
500433d6423SLionel Sambuc  * DESCRIPTION: This function is called to determine the space required to
501433d6423SLionel Sambuc  *              contain a simple object for return to an external user.
502433d6423SLionel Sambuc  *
503433d6423SLionel Sambuc  *              The length includes the object structure plus any additional
504433d6423SLionel Sambuc  *              needed space.
505433d6423SLionel Sambuc  *
506433d6423SLionel Sambuc  ******************************************************************************/
507433d6423SLionel Sambuc 
508433d6423SLionel Sambuc static ACPI_STATUS
AcpiUtGetSimpleObjectSize(ACPI_OPERAND_OBJECT * InternalObject,ACPI_SIZE * ObjLength)509433d6423SLionel Sambuc AcpiUtGetSimpleObjectSize (
510433d6423SLionel Sambuc     ACPI_OPERAND_OBJECT     *InternalObject,
511433d6423SLionel Sambuc     ACPI_SIZE               *ObjLength)
512433d6423SLionel Sambuc {
513433d6423SLionel Sambuc     ACPI_SIZE               Length;
514433d6423SLionel Sambuc     ACPI_SIZE               Size;
515433d6423SLionel Sambuc     ACPI_STATUS             Status = AE_OK;
516433d6423SLionel Sambuc 
517433d6423SLionel Sambuc 
518433d6423SLionel Sambuc     ACPI_FUNCTION_TRACE_PTR (UtGetSimpleObjectSize, InternalObject);
519433d6423SLionel Sambuc 
520433d6423SLionel Sambuc 
521433d6423SLionel Sambuc     /* Start with the length of the (external) Acpi object */
522433d6423SLionel Sambuc 
523433d6423SLionel Sambuc     Length = sizeof (ACPI_OBJECT);
524433d6423SLionel Sambuc 
525433d6423SLionel Sambuc     /* A NULL object is allowed, can be a legal uninitialized package element */
526433d6423SLionel Sambuc 
527433d6423SLionel Sambuc     if (!InternalObject)
528433d6423SLionel Sambuc     {
529433d6423SLionel Sambuc         /*
530433d6423SLionel Sambuc          * Object is NULL, just return the length of ACPI_OBJECT
531433d6423SLionel Sambuc          * (A NULL ACPI_OBJECT is an object of all zeroes.)
532433d6423SLionel Sambuc          */
533433d6423SLionel Sambuc         *ObjLength = ACPI_ROUND_UP_TO_NATIVE_WORD (Length);
534433d6423SLionel Sambuc         return_ACPI_STATUS (AE_OK);
535433d6423SLionel Sambuc     }
536433d6423SLionel Sambuc 
537433d6423SLionel Sambuc     /* A Namespace Node should never appear here */
538433d6423SLionel Sambuc 
539433d6423SLionel Sambuc     if (ACPI_GET_DESCRIPTOR_TYPE (InternalObject) == ACPI_DESC_TYPE_NAMED)
540433d6423SLionel Sambuc     {
541433d6423SLionel Sambuc         /* A namespace node should never get here */
542433d6423SLionel Sambuc 
543433d6423SLionel Sambuc         return_ACPI_STATUS (AE_AML_INTERNAL);
544433d6423SLionel Sambuc     }
545433d6423SLionel Sambuc 
546433d6423SLionel Sambuc     /*
547433d6423SLionel Sambuc      * The final length depends on the object type
548433d6423SLionel Sambuc      * Strings and Buffers are packed right up against the parent object and
549433d6423SLionel Sambuc      * must be accessed bytewise or there may be alignment problems on
550433d6423SLionel Sambuc      * certain processors
551433d6423SLionel Sambuc      */
552433d6423SLionel Sambuc     switch (InternalObject->Common.Type)
553433d6423SLionel Sambuc     {
554433d6423SLionel Sambuc     case ACPI_TYPE_STRING:
555433d6423SLionel Sambuc 
556433d6423SLionel Sambuc         Length += (ACPI_SIZE) InternalObject->String.Length + 1;
557433d6423SLionel Sambuc         break;
558433d6423SLionel Sambuc 
559433d6423SLionel Sambuc     case ACPI_TYPE_BUFFER:
560433d6423SLionel Sambuc 
561433d6423SLionel Sambuc         Length += (ACPI_SIZE) InternalObject->Buffer.Length;
562433d6423SLionel Sambuc         break;
563433d6423SLionel Sambuc 
564433d6423SLionel Sambuc     case ACPI_TYPE_INTEGER:
565433d6423SLionel Sambuc     case ACPI_TYPE_PROCESSOR:
566433d6423SLionel Sambuc     case ACPI_TYPE_POWER:
567433d6423SLionel Sambuc 
568433d6423SLionel Sambuc         /* No extra data for these types */
569433d6423SLionel Sambuc 
570433d6423SLionel Sambuc         break;
571433d6423SLionel Sambuc 
572433d6423SLionel Sambuc     case ACPI_TYPE_LOCAL_REFERENCE:
573433d6423SLionel Sambuc 
574433d6423SLionel Sambuc         switch (InternalObject->Reference.Class)
575433d6423SLionel Sambuc         {
576433d6423SLionel Sambuc         case ACPI_REFCLASS_NAME:
577433d6423SLionel Sambuc             /*
578433d6423SLionel Sambuc              * Get the actual length of the full pathname to this object.
579433d6423SLionel Sambuc              * The reference will be converted to the pathname to the object
580433d6423SLionel Sambuc              */
581433d6423SLionel Sambuc             Size = AcpiNsGetPathnameLength (InternalObject->Reference.Node);
582433d6423SLionel Sambuc             if (!Size)
583433d6423SLionel Sambuc             {
584433d6423SLionel Sambuc                 return_ACPI_STATUS (AE_BAD_PARAMETER);
585433d6423SLionel Sambuc             }
586433d6423SLionel Sambuc 
587433d6423SLionel Sambuc             Length += ACPI_ROUND_UP_TO_NATIVE_WORD (Size);
588433d6423SLionel Sambuc             break;
589433d6423SLionel Sambuc 
590433d6423SLionel Sambuc         default:
591433d6423SLionel Sambuc             /*
592433d6423SLionel Sambuc              * No other reference opcodes are supported.
593433d6423SLionel Sambuc              * Notably, Locals and Args are not supported, but this may be
594433d6423SLionel Sambuc              * required eventually.
595433d6423SLionel Sambuc              */
596433d6423SLionel Sambuc             ACPI_ERROR ((AE_INFO, "Cannot convert to external object - "
597433d6423SLionel Sambuc                 "unsupported Reference Class [%s] 0x%X in object %p",
598433d6423SLionel Sambuc                 AcpiUtGetReferenceName (InternalObject),
599433d6423SLionel Sambuc                 InternalObject->Reference.Class, InternalObject));
600433d6423SLionel Sambuc             Status = AE_TYPE;
601433d6423SLionel Sambuc             break;
602433d6423SLionel Sambuc         }
603433d6423SLionel Sambuc         break;
604433d6423SLionel Sambuc 
605433d6423SLionel Sambuc     default:
606433d6423SLionel Sambuc 
607433d6423SLionel Sambuc         ACPI_ERROR ((AE_INFO, "Cannot convert to external object - "
608433d6423SLionel Sambuc             "unsupported type [%s] 0x%X in object %p",
609433d6423SLionel Sambuc             AcpiUtGetObjectTypeName (InternalObject),
610433d6423SLionel Sambuc             InternalObject->Common.Type, InternalObject));
611433d6423SLionel Sambuc         Status = AE_TYPE;
612433d6423SLionel Sambuc         break;
613433d6423SLionel Sambuc     }
614433d6423SLionel Sambuc 
615433d6423SLionel Sambuc     /*
616433d6423SLionel Sambuc      * Account for the space required by the object rounded up to the next
617433d6423SLionel Sambuc      * multiple of the machine word size. This keeps each object aligned
618433d6423SLionel Sambuc      * on a machine word boundary. (preventing alignment faults on some
619433d6423SLionel Sambuc      * machines.)
620433d6423SLionel Sambuc      */
621433d6423SLionel Sambuc     *ObjLength = ACPI_ROUND_UP_TO_NATIVE_WORD (Length);
622433d6423SLionel Sambuc     return_ACPI_STATUS (Status);
623433d6423SLionel Sambuc }
624433d6423SLionel Sambuc 
625433d6423SLionel Sambuc 
626433d6423SLionel Sambuc /*******************************************************************************
627433d6423SLionel Sambuc  *
628433d6423SLionel Sambuc  * FUNCTION:    AcpiUtGetElementLength
629433d6423SLionel Sambuc  *
630433d6423SLionel Sambuc  * PARAMETERS:  ACPI_PKG_CALLBACK
631433d6423SLionel Sambuc  *
632433d6423SLionel Sambuc  * RETURN:      Status
633433d6423SLionel Sambuc  *
634433d6423SLionel Sambuc  * DESCRIPTION: Get the length of one package element.
635433d6423SLionel Sambuc  *
636433d6423SLionel Sambuc  ******************************************************************************/
637433d6423SLionel Sambuc 
638433d6423SLionel Sambuc static ACPI_STATUS
AcpiUtGetElementLength(UINT8 ObjectType,ACPI_OPERAND_OBJECT * SourceObject,ACPI_GENERIC_STATE * State,void * Context)639433d6423SLionel Sambuc AcpiUtGetElementLength (
640433d6423SLionel Sambuc     UINT8                   ObjectType,
641433d6423SLionel Sambuc     ACPI_OPERAND_OBJECT     *SourceObject,
642433d6423SLionel Sambuc     ACPI_GENERIC_STATE      *State,
643433d6423SLionel Sambuc     void                    *Context)
644433d6423SLionel Sambuc {
645433d6423SLionel Sambuc     ACPI_STATUS             Status = AE_OK;
646433d6423SLionel Sambuc     ACPI_PKG_INFO           *Info = (ACPI_PKG_INFO *) Context;
647433d6423SLionel Sambuc     ACPI_SIZE               ObjectSpace;
648433d6423SLionel Sambuc 
649433d6423SLionel Sambuc 
650433d6423SLionel Sambuc     switch (ObjectType)
651433d6423SLionel Sambuc     {
652433d6423SLionel Sambuc     case ACPI_COPY_TYPE_SIMPLE:
653433d6423SLionel Sambuc         /*
654433d6423SLionel Sambuc          * Simple object - just get the size (Null object/entry is handled
655433d6423SLionel Sambuc          * here also) and sum it into the running package length
656433d6423SLionel Sambuc          */
657433d6423SLionel Sambuc         Status = AcpiUtGetSimpleObjectSize (SourceObject, &ObjectSpace);
658433d6423SLionel Sambuc         if (ACPI_FAILURE (Status))
659433d6423SLionel Sambuc         {
660433d6423SLionel Sambuc             return (Status);
661433d6423SLionel Sambuc         }
662433d6423SLionel Sambuc 
663433d6423SLionel Sambuc         Info->Length += ObjectSpace;
664433d6423SLionel Sambuc         break;
665433d6423SLionel Sambuc 
666433d6423SLionel Sambuc     case ACPI_COPY_TYPE_PACKAGE:
667433d6423SLionel Sambuc 
668433d6423SLionel Sambuc         /* Package object - nothing much to do here, let the walk handle it */
669433d6423SLionel Sambuc 
670433d6423SLionel Sambuc         Info->NumPackages++;
671433d6423SLionel Sambuc         State->Pkg.ThisTargetObj = NULL;
672433d6423SLionel Sambuc         break;
673433d6423SLionel Sambuc 
674433d6423SLionel Sambuc     default:
675433d6423SLionel Sambuc 
676433d6423SLionel Sambuc         /* No other types allowed */
677433d6423SLionel Sambuc 
678433d6423SLionel Sambuc         return (AE_BAD_PARAMETER);
679433d6423SLionel Sambuc     }
680433d6423SLionel Sambuc 
681433d6423SLionel Sambuc     return (Status);
682433d6423SLionel Sambuc }
683433d6423SLionel Sambuc 
684433d6423SLionel Sambuc 
685433d6423SLionel Sambuc /*******************************************************************************
686433d6423SLionel Sambuc  *
687433d6423SLionel Sambuc  * FUNCTION:    AcpiUtGetPackageObjectSize
688433d6423SLionel Sambuc  *
689433d6423SLionel Sambuc  * PARAMETERS:  InternalObject      - An ACPI internal object
690433d6423SLionel Sambuc  *              ObjLength           - Where the length is returned
691433d6423SLionel Sambuc  *
692433d6423SLionel Sambuc  * RETURN:      Status
693433d6423SLionel Sambuc  *
694433d6423SLionel Sambuc  * DESCRIPTION: This function is called to determine the space required to
695433d6423SLionel Sambuc  *              contain a package object for return to an external user.
696433d6423SLionel Sambuc  *
697433d6423SLionel Sambuc  *              This is moderately complex since a package contains other
698433d6423SLionel Sambuc  *              objects including packages.
699433d6423SLionel Sambuc  *
700433d6423SLionel Sambuc  ******************************************************************************/
701433d6423SLionel Sambuc 
702433d6423SLionel Sambuc static ACPI_STATUS
AcpiUtGetPackageObjectSize(ACPI_OPERAND_OBJECT * InternalObject,ACPI_SIZE * ObjLength)703433d6423SLionel Sambuc AcpiUtGetPackageObjectSize (
704433d6423SLionel Sambuc     ACPI_OPERAND_OBJECT     *InternalObject,
705433d6423SLionel Sambuc     ACPI_SIZE               *ObjLength)
706433d6423SLionel Sambuc {
707433d6423SLionel Sambuc     ACPI_STATUS             Status;
708433d6423SLionel Sambuc     ACPI_PKG_INFO           Info;
709433d6423SLionel Sambuc 
710433d6423SLionel Sambuc 
711433d6423SLionel Sambuc     ACPI_FUNCTION_TRACE_PTR (UtGetPackageObjectSize, InternalObject);
712433d6423SLionel Sambuc 
713433d6423SLionel Sambuc 
714433d6423SLionel Sambuc     Info.Length      = 0;
715433d6423SLionel Sambuc     Info.ObjectSpace = 0;
716433d6423SLionel Sambuc     Info.NumPackages = 1;
717433d6423SLionel Sambuc 
718433d6423SLionel Sambuc     Status = AcpiUtWalkPackageTree (InternalObject, NULL,
719433d6423SLionel Sambuc         AcpiUtGetElementLength, &Info);
720433d6423SLionel Sambuc     if (ACPI_FAILURE (Status))
721433d6423SLionel Sambuc     {
722433d6423SLionel Sambuc         return_ACPI_STATUS (Status);
723433d6423SLionel Sambuc     }
724433d6423SLionel Sambuc 
725433d6423SLionel Sambuc     /*
726433d6423SLionel Sambuc      * We have handled all of the objects in all levels of the package.
727433d6423SLionel Sambuc      * just add the length of the package objects themselves.
728433d6423SLionel Sambuc      * Round up to the next machine word.
729433d6423SLionel Sambuc      */
730433d6423SLionel Sambuc     Info.Length += ACPI_ROUND_UP_TO_NATIVE_WORD (sizeof (ACPI_OBJECT)) *
731433d6423SLionel Sambuc                     (ACPI_SIZE) Info.NumPackages;
732433d6423SLionel Sambuc 
733433d6423SLionel Sambuc     /* Return the total package length */
734433d6423SLionel Sambuc 
735433d6423SLionel Sambuc     *ObjLength = Info.Length;
736433d6423SLionel Sambuc     return_ACPI_STATUS (Status);
737433d6423SLionel Sambuc }
738433d6423SLionel Sambuc 
739433d6423SLionel Sambuc 
740433d6423SLionel Sambuc /*******************************************************************************
741433d6423SLionel Sambuc  *
742433d6423SLionel Sambuc  * FUNCTION:    AcpiUtGetObjectSize
743433d6423SLionel Sambuc  *
744433d6423SLionel Sambuc  * PARAMETERS:  InternalObject      - An ACPI internal object
745433d6423SLionel Sambuc  *              ObjLength           - Where the length will be returned
746433d6423SLionel Sambuc  *
747433d6423SLionel Sambuc  * RETURN:      Status
748433d6423SLionel Sambuc  *
749433d6423SLionel Sambuc  * DESCRIPTION: This function is called to determine the space required to
750433d6423SLionel Sambuc  *              contain an object for return to an API user.
751433d6423SLionel Sambuc  *
752433d6423SLionel Sambuc  ******************************************************************************/
753433d6423SLionel Sambuc 
754433d6423SLionel Sambuc ACPI_STATUS
AcpiUtGetObjectSize(ACPI_OPERAND_OBJECT * InternalObject,ACPI_SIZE * ObjLength)755433d6423SLionel Sambuc AcpiUtGetObjectSize (
756433d6423SLionel Sambuc     ACPI_OPERAND_OBJECT     *InternalObject,
757433d6423SLionel Sambuc     ACPI_SIZE               *ObjLength)
758433d6423SLionel Sambuc {
759433d6423SLionel Sambuc     ACPI_STATUS             Status;
760433d6423SLionel Sambuc 
761433d6423SLionel Sambuc 
762433d6423SLionel Sambuc     ACPI_FUNCTION_ENTRY ();
763433d6423SLionel Sambuc 
764433d6423SLionel Sambuc 
765433d6423SLionel Sambuc     if ((ACPI_GET_DESCRIPTOR_TYPE (InternalObject) == ACPI_DESC_TYPE_OPERAND) &&
766433d6423SLionel Sambuc         (InternalObject->Common.Type == ACPI_TYPE_PACKAGE))
767433d6423SLionel Sambuc     {
768433d6423SLionel Sambuc         Status = AcpiUtGetPackageObjectSize (InternalObject, ObjLength);
769433d6423SLionel Sambuc     }
770433d6423SLionel Sambuc     else
771433d6423SLionel Sambuc     {
772433d6423SLionel Sambuc         Status = AcpiUtGetSimpleObjectSize (InternalObject, ObjLength);
773433d6423SLionel Sambuc     }
774433d6423SLionel Sambuc 
775433d6423SLionel Sambuc     return (Status);
776433d6423SLionel Sambuc }
777