xref: /titanic_44/usr/src/uts/intel/io/acpica/utilities/utobject.c (revision cb56572868bfc488bbd3ab847b09db2a25554d44)
1ae115bc7Smrj /******************************************************************************
2ae115bc7Smrj  *
3ae115bc7Smrj  * Module Name: utobject - ACPI object create/delete/size/cache routines
4ae115bc7Smrj  *
5ae115bc7Smrj  *****************************************************************************/
6ae115bc7Smrj 
726f3cdf0SGordon Ross /*
8*cb565728SJerry Jelinek  * Copyright (C) 2000 - 2016, Intel Corp.
9ae115bc7Smrj  * All rights reserved.
10ae115bc7Smrj  *
1126f3cdf0SGordon Ross  * Redistribution and use in source and binary forms, with or without
1226f3cdf0SGordon Ross  * modification, are permitted provided that the following conditions
1326f3cdf0SGordon Ross  * are met:
1426f3cdf0SGordon Ross  * 1. Redistributions of source code must retain the above copyright
1526f3cdf0SGordon Ross  *    notice, this list of conditions, and the following disclaimer,
1626f3cdf0SGordon Ross  *    without modification.
1726f3cdf0SGordon Ross  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
1826f3cdf0SGordon Ross  *    substantially similar to the "NO WARRANTY" disclaimer below
1926f3cdf0SGordon Ross  *    ("Disclaimer") and any redistribution must be conditioned upon
2026f3cdf0SGordon Ross  *    including a substantially similar Disclaimer requirement for further
2126f3cdf0SGordon Ross  *    binary redistribution.
2226f3cdf0SGordon Ross  * 3. Neither the names of the above-listed copyright holders nor the names
2326f3cdf0SGordon Ross  *    of any contributors may be used to endorse or promote products derived
2426f3cdf0SGordon Ross  *    from this software without specific prior written permission.
25ae115bc7Smrj  *
2626f3cdf0SGordon Ross  * Alternatively, this software may be distributed under the terms of the
2726f3cdf0SGordon Ross  * GNU General Public License ("GPL") version 2 as published by the Free
2826f3cdf0SGordon Ross  * Software Foundation.
29ae115bc7Smrj  *
3026f3cdf0SGordon Ross  * NO WARRANTY
3126f3cdf0SGordon Ross  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
3226f3cdf0SGordon Ross  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
3326f3cdf0SGordon Ross  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
3426f3cdf0SGordon Ross  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
3526f3cdf0SGordon Ross  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
3626f3cdf0SGordon Ross  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
3726f3cdf0SGordon Ross  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3826f3cdf0SGordon Ross  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
3926f3cdf0SGordon Ross  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
4026f3cdf0SGordon Ross  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
4126f3cdf0SGordon Ross  * POSSIBILITY OF SUCH DAMAGES.
4226f3cdf0SGordon Ross  */
43ae115bc7Smrj 
44ae115bc7Smrj #include "acpi.h"
45aa2aa9a6SDana Myers #include "accommon.h"
46ae115bc7Smrj #include "acnamesp.h"
47ae115bc7Smrj 
48ae115bc7Smrj 
49ae115bc7Smrj #define _COMPONENT          ACPI_UTILITIES
50ae115bc7Smrj         ACPI_MODULE_NAME    ("utobject")
51ae115bc7Smrj 
52ae115bc7Smrj /* Local prototypes */
53ae115bc7Smrj 
54ae115bc7Smrj static ACPI_STATUS
55ae115bc7Smrj AcpiUtGetSimpleObjectSize (
56ae115bc7Smrj     ACPI_OPERAND_OBJECT     *Obj,
57ae115bc7Smrj     ACPI_SIZE               *ObjLength);
58ae115bc7Smrj 
59ae115bc7Smrj static ACPI_STATUS
60ae115bc7Smrj AcpiUtGetPackageObjectSize (
61ae115bc7Smrj     ACPI_OPERAND_OBJECT     *Obj,
62ae115bc7Smrj     ACPI_SIZE               *ObjLength);
63ae115bc7Smrj 
64ae115bc7Smrj static ACPI_STATUS
65ae115bc7Smrj AcpiUtGetElementLength (
66ae115bc7Smrj     UINT8                   ObjectType,
67ae115bc7Smrj     ACPI_OPERAND_OBJECT     *SourceObject,
68ae115bc7Smrj     ACPI_GENERIC_STATE      *State,
69ae115bc7Smrj     void                    *Context);
70ae115bc7Smrj 
71ae115bc7Smrj 
72ae115bc7Smrj /*******************************************************************************
73ae115bc7Smrj  *
74ae115bc7Smrj  * FUNCTION:    AcpiUtCreateInternalObjectDbg
75ae115bc7Smrj  *
76ae115bc7Smrj  * PARAMETERS:  ModuleName          - Source file name of caller
77ae115bc7Smrj  *              LineNumber          - Line number of caller
78ae115bc7Smrj  *              ComponentId         - Component type of caller
79ae115bc7Smrj  *              Type                - ACPI Type of the new object
80ae115bc7Smrj  *
81ae115bc7Smrj  * RETURN:      A new internal object, null on failure
82ae115bc7Smrj  *
83ae115bc7Smrj  * DESCRIPTION: Create and initialize a new internal object.
84ae115bc7Smrj  *
85ae115bc7Smrj  * NOTE:        We always allocate the worst-case object descriptor because
86ae115bc7Smrj  *              these objects are cached, and we want them to be
87ae115bc7Smrj  *              one-size-satisifies-any-request. This in itself may not be
88ae115bc7Smrj  *              the most memory efficient, but the efficiency of the object
89ae115bc7Smrj  *              cache should more than make up for this!
90ae115bc7Smrj  *
91ae115bc7Smrj  ******************************************************************************/
92ae115bc7Smrj 
93ae115bc7Smrj ACPI_OPERAND_OBJECT  *
AcpiUtCreateInternalObjectDbg(const char * ModuleName,UINT32 LineNumber,UINT32 ComponentId,ACPI_OBJECT_TYPE Type)94ae115bc7Smrj AcpiUtCreateInternalObjectDbg (
95db2bae30SDana Myers     const char              *ModuleName,
96ae115bc7Smrj     UINT32                  LineNumber,
97ae115bc7Smrj     UINT32                  ComponentId,
98ae115bc7Smrj     ACPI_OBJECT_TYPE        Type)
99ae115bc7Smrj {
100ae115bc7Smrj     ACPI_OPERAND_OBJECT     *Object;
101ae115bc7Smrj     ACPI_OPERAND_OBJECT     *SecondObject;
102ae115bc7Smrj 
103ae115bc7Smrj 
104ae115bc7Smrj     ACPI_FUNCTION_TRACE_STR (UtCreateInternalObjectDbg,
105ae115bc7Smrj         AcpiUtGetTypeName (Type));
106ae115bc7Smrj 
107ae115bc7Smrj 
108ae115bc7Smrj     /* Allocate the raw object descriptor */
109ae115bc7Smrj 
110*cb565728SJerry Jelinek     Object = AcpiUtAllocateObjectDescDbg (
111*cb565728SJerry Jelinek         ModuleName, LineNumber, ComponentId);
112ae115bc7Smrj     if (!Object)
113ae115bc7Smrj     {
114ae115bc7Smrj         return_PTR (NULL);
115ae115bc7Smrj     }
116ae115bc7Smrj 
117ae115bc7Smrj     switch (Type)
118ae115bc7Smrj     {
119ae115bc7Smrj     case ACPI_TYPE_REGION:
120ae115bc7Smrj     case ACPI_TYPE_BUFFER_FIELD:
121db2bae30SDana Myers     case ACPI_TYPE_LOCAL_BANK_FIELD:
122ae115bc7Smrj 
123ae115bc7Smrj         /* These types require a secondary object */
124ae115bc7Smrj 
125*cb565728SJerry Jelinek         SecondObject = AcpiUtAllocateObjectDescDbg (
126*cb565728SJerry Jelinek             ModuleName, LineNumber, ComponentId);
127ae115bc7Smrj         if (!SecondObject)
128ae115bc7Smrj         {
129ae115bc7Smrj             AcpiUtDeleteObjectDesc (Object);
130ae115bc7Smrj             return_PTR (NULL);
131ae115bc7Smrj         }
132ae115bc7Smrj 
133ae115bc7Smrj         SecondObject->Common.Type = ACPI_TYPE_LOCAL_EXTRA;
134ae115bc7Smrj         SecondObject->Common.ReferenceCount = 1;
135ae115bc7Smrj 
136ae115bc7Smrj         /* Link the second object to the first */
137ae115bc7Smrj 
138ae115bc7Smrj         Object->Common.NextObject = SecondObject;
139ae115bc7Smrj         break;
140ae115bc7Smrj 
141ae115bc7Smrj     default:
142*cb565728SJerry Jelinek 
143ae115bc7Smrj         /* All others have no secondary object */
144ae115bc7Smrj         break;
145ae115bc7Smrj     }
146ae115bc7Smrj 
147ae115bc7Smrj     /* Save the object type in the object descriptor */
148ae115bc7Smrj 
149ae115bc7Smrj     Object->Common.Type = (UINT8) Type;
150ae115bc7Smrj 
151ae115bc7Smrj     /* Init the reference count */
152ae115bc7Smrj 
153ae115bc7Smrj     Object->Common.ReferenceCount = 1;
154ae115bc7Smrj 
155ae115bc7Smrj     /* Any per-type initialization should go here */
156ae115bc7Smrj 
157ae115bc7Smrj     return_PTR (Object);
158ae115bc7Smrj }
159ae115bc7Smrj 
160ae115bc7Smrj 
161ae115bc7Smrj /*******************************************************************************
162ae115bc7Smrj  *
163db2bae30SDana Myers  * FUNCTION:    AcpiUtCreatePackageObject
164db2bae30SDana Myers  *
165db2bae30SDana Myers  * PARAMETERS:  Count               - Number of package elements
166db2bae30SDana Myers  *
167db2bae30SDana Myers  * RETURN:      Pointer to a new Package object, null on failure
168db2bae30SDana Myers  *
169db2bae30SDana Myers  * DESCRIPTION: Create a fully initialized package object
170db2bae30SDana Myers  *
171db2bae30SDana Myers  ******************************************************************************/
172db2bae30SDana Myers 
173db2bae30SDana Myers ACPI_OPERAND_OBJECT *
AcpiUtCreatePackageObject(UINT32 Count)174db2bae30SDana Myers AcpiUtCreatePackageObject (
175db2bae30SDana Myers     UINT32                  Count)
176db2bae30SDana Myers {
177db2bae30SDana Myers     ACPI_OPERAND_OBJECT     *PackageDesc;
178db2bae30SDana Myers     ACPI_OPERAND_OBJECT     **PackageElements;
179db2bae30SDana Myers 
180db2bae30SDana Myers 
181db2bae30SDana Myers     ACPI_FUNCTION_TRACE_U32 (UtCreatePackageObject, Count);
182db2bae30SDana Myers 
183db2bae30SDana Myers 
184db2bae30SDana Myers     /* Create a new Package object */
185db2bae30SDana Myers 
186db2bae30SDana Myers     PackageDesc = AcpiUtCreateInternalObject (ACPI_TYPE_PACKAGE);
187db2bae30SDana Myers     if (!PackageDesc)
188db2bae30SDana Myers     {
189db2bae30SDana Myers         return_PTR (NULL);
190db2bae30SDana Myers     }
191db2bae30SDana Myers 
192db2bae30SDana Myers     /*
193db2bae30SDana Myers      * Create the element array. Count+1 allows the array to be null
194db2bae30SDana Myers      * terminated.
195db2bae30SDana Myers      */
196db2bae30SDana Myers     PackageElements = ACPI_ALLOCATE_ZEROED (
197db2bae30SDana Myers         ((ACPI_SIZE) Count + 1) * sizeof (void *));
198db2bae30SDana Myers     if (!PackageElements)
199db2bae30SDana Myers     {
200db2bae30SDana Myers         ACPI_FREE (PackageDesc);
201db2bae30SDana Myers         return_PTR (NULL);
202db2bae30SDana Myers     }
203db2bae30SDana Myers 
204db2bae30SDana Myers     PackageDesc->Package.Count = Count;
205db2bae30SDana Myers     PackageDesc->Package.Elements = PackageElements;
206db2bae30SDana Myers     return_PTR (PackageDesc);
207db2bae30SDana Myers }
208db2bae30SDana Myers 
209db2bae30SDana Myers 
210db2bae30SDana Myers /*******************************************************************************
211db2bae30SDana Myers  *
21257190917SDana Myers  * FUNCTION:    AcpiUtCreateIntegerObject
21357190917SDana Myers  *
21457190917SDana Myers  * PARAMETERS:  InitialValue        - Initial value for the integer
21557190917SDana Myers  *
21657190917SDana Myers  * RETURN:      Pointer to a new Integer object, null on failure
21757190917SDana Myers  *
21857190917SDana Myers  * DESCRIPTION: Create an initialized integer object
21957190917SDana Myers  *
22057190917SDana Myers  ******************************************************************************/
22157190917SDana Myers 
22257190917SDana Myers ACPI_OPERAND_OBJECT *
AcpiUtCreateIntegerObject(UINT64 InitialValue)22357190917SDana Myers AcpiUtCreateIntegerObject (
22457190917SDana Myers     UINT64                  InitialValue)
22557190917SDana Myers {
22657190917SDana Myers     ACPI_OPERAND_OBJECT     *IntegerDesc;
22757190917SDana Myers 
22857190917SDana Myers 
22957190917SDana Myers     ACPI_FUNCTION_TRACE (UtCreateIntegerObject);
23057190917SDana Myers 
23157190917SDana Myers 
23257190917SDana Myers     /* Create and initialize a new integer object */
23357190917SDana Myers 
23457190917SDana Myers     IntegerDesc = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
23557190917SDana Myers     if (!IntegerDesc)
23657190917SDana Myers     {
23757190917SDana Myers         return_PTR (NULL);
23857190917SDana Myers     }
23957190917SDana Myers 
24057190917SDana Myers     IntegerDesc->Integer.Value = InitialValue;
24157190917SDana Myers     return_PTR (IntegerDesc);
24257190917SDana Myers }
24357190917SDana Myers 
24457190917SDana Myers 
24557190917SDana Myers /*******************************************************************************
24657190917SDana Myers  *
247ae115bc7Smrj  * FUNCTION:    AcpiUtCreateBufferObject
248ae115bc7Smrj  *
249ae115bc7Smrj  * PARAMETERS:  BufferSize             - Size of buffer to be created
250ae115bc7Smrj  *
251ae115bc7Smrj  * RETURN:      Pointer to a new Buffer object, null on failure
252ae115bc7Smrj  *
253ae115bc7Smrj  * DESCRIPTION: Create a fully initialized buffer object
254ae115bc7Smrj  *
255ae115bc7Smrj  ******************************************************************************/
256ae115bc7Smrj 
257ae115bc7Smrj ACPI_OPERAND_OBJECT *
AcpiUtCreateBufferObject(ACPI_SIZE BufferSize)258ae115bc7Smrj AcpiUtCreateBufferObject (
259ae115bc7Smrj     ACPI_SIZE               BufferSize)
260ae115bc7Smrj {
261ae115bc7Smrj     ACPI_OPERAND_OBJECT     *BufferDesc;
262ae115bc7Smrj     UINT8                   *Buffer = NULL;
263ae115bc7Smrj 
264ae115bc7Smrj 
265ae115bc7Smrj     ACPI_FUNCTION_TRACE_U32 (UtCreateBufferObject, BufferSize);
266ae115bc7Smrj 
267ae115bc7Smrj 
268ae115bc7Smrj     /* Create a new Buffer object */
269ae115bc7Smrj 
270ae115bc7Smrj     BufferDesc = AcpiUtCreateInternalObject (ACPI_TYPE_BUFFER);
271ae115bc7Smrj     if (!BufferDesc)
272ae115bc7Smrj     {
273ae115bc7Smrj         return_PTR (NULL);
274ae115bc7Smrj     }
275ae115bc7Smrj 
276ae115bc7Smrj     /* Create an actual buffer only if size > 0 */
277ae115bc7Smrj 
278ae115bc7Smrj     if (BufferSize > 0)
279ae115bc7Smrj     {
280ae115bc7Smrj         /* Allocate the actual buffer */
281ae115bc7Smrj 
282ae115bc7Smrj         Buffer = ACPI_ALLOCATE_ZEROED (BufferSize);
283ae115bc7Smrj         if (!Buffer)
284ae115bc7Smrj         {
28526f3cdf0SGordon Ross             ACPI_ERROR ((AE_INFO, "Could not allocate size %u",
286ae115bc7Smrj                 (UINT32) BufferSize));
287*cb565728SJerry Jelinek 
288ae115bc7Smrj             AcpiUtRemoveReference (BufferDesc);
289ae115bc7Smrj             return_PTR (NULL);
290ae115bc7Smrj         }
291ae115bc7Smrj     }
292ae115bc7Smrj 
293ae115bc7Smrj     /* Complete buffer object initialization */
294ae115bc7Smrj 
295ae115bc7Smrj     BufferDesc->Buffer.Flags |= AOPOBJ_DATA_VALID;
296ae115bc7Smrj     BufferDesc->Buffer.Pointer = Buffer;
297ae115bc7Smrj     BufferDesc->Buffer.Length = (UINT32) BufferSize;
298ae115bc7Smrj 
299ae115bc7Smrj     /* Return the new buffer descriptor */
300ae115bc7Smrj 
301ae115bc7Smrj     return_PTR (BufferDesc);
302ae115bc7Smrj }
303ae115bc7Smrj 
304ae115bc7Smrj 
305ae115bc7Smrj /*******************************************************************************
306ae115bc7Smrj  *
307ae115bc7Smrj  * FUNCTION:    AcpiUtCreateStringObject
308ae115bc7Smrj  *
309ae115bc7Smrj  * PARAMETERS:  StringSize          - Size of string to be created. Does not
310ae115bc7Smrj  *                                    include NULL terminator, this is added
311ae115bc7Smrj  *                                    automatically.
312ae115bc7Smrj  *
313ae115bc7Smrj  * RETURN:      Pointer to a new String object
314ae115bc7Smrj  *
315ae115bc7Smrj  * DESCRIPTION: Create a fully initialized string object
316ae115bc7Smrj  *
317ae115bc7Smrj  ******************************************************************************/
318ae115bc7Smrj 
319ae115bc7Smrj ACPI_OPERAND_OBJECT *
AcpiUtCreateStringObject(ACPI_SIZE StringSize)320ae115bc7Smrj AcpiUtCreateStringObject (
321ae115bc7Smrj     ACPI_SIZE               StringSize)
322ae115bc7Smrj {
323ae115bc7Smrj     ACPI_OPERAND_OBJECT     *StringDesc;
324ae115bc7Smrj     char                    *String;
325ae115bc7Smrj 
326ae115bc7Smrj 
327ae115bc7Smrj     ACPI_FUNCTION_TRACE_U32 (UtCreateStringObject, StringSize);
328ae115bc7Smrj 
329ae115bc7Smrj 
330ae115bc7Smrj     /* Create a new String object */
331ae115bc7Smrj 
332ae115bc7Smrj     StringDesc = AcpiUtCreateInternalObject (ACPI_TYPE_STRING);
333ae115bc7Smrj     if (!StringDesc)
334ae115bc7Smrj     {
335ae115bc7Smrj         return_PTR (NULL);
336ae115bc7Smrj     }
337ae115bc7Smrj 
338ae115bc7Smrj     /*
339ae115bc7Smrj      * Allocate the actual string buffer -- (Size + 1) for NULL terminator.
340ae115bc7Smrj      * NOTE: Zero-length strings are NULL terminated
341ae115bc7Smrj      */
342ae115bc7Smrj     String = ACPI_ALLOCATE_ZEROED (StringSize + 1);
343ae115bc7Smrj     if (!String)
344ae115bc7Smrj     {
34526f3cdf0SGordon Ross         ACPI_ERROR ((AE_INFO, "Could not allocate size %u",
346ae115bc7Smrj             (UINT32) StringSize));
347*cb565728SJerry Jelinek 
348ae115bc7Smrj         AcpiUtRemoveReference (StringDesc);
349ae115bc7Smrj         return_PTR (NULL);
350ae115bc7Smrj     }
351ae115bc7Smrj 
352ae115bc7Smrj     /* Complete string object initialization */
353ae115bc7Smrj 
354ae115bc7Smrj     StringDesc->String.Pointer = String;
355ae115bc7Smrj     StringDesc->String.Length = (UINT32) StringSize;
356ae115bc7Smrj 
357ae115bc7Smrj     /* Return the new string descriptor */
358ae115bc7Smrj 
359ae115bc7Smrj     return_PTR (StringDesc);
360ae115bc7Smrj }
361ae115bc7Smrj 
362ae115bc7Smrj 
363ae115bc7Smrj /*******************************************************************************
364ae115bc7Smrj  *
365ae115bc7Smrj  * FUNCTION:    AcpiUtValidInternalObject
366ae115bc7Smrj  *
367ae115bc7Smrj  * PARAMETERS:  Object              - Object to be validated
368ae115bc7Smrj  *
369ae115bc7Smrj  * RETURN:      TRUE if object is valid, FALSE otherwise
370ae115bc7Smrj  *
371*cb565728SJerry Jelinek  * DESCRIPTION: Validate a pointer to be of type ACPI_OPERAND_OBJECT
372ae115bc7Smrj  *
373ae115bc7Smrj  ******************************************************************************/
374ae115bc7Smrj 
375ae115bc7Smrj BOOLEAN
AcpiUtValidInternalObject(void * Object)376ae115bc7Smrj AcpiUtValidInternalObject (
377ae115bc7Smrj     void                    *Object)
378ae115bc7Smrj {
379ae115bc7Smrj 
380ae115bc7Smrj     ACPI_FUNCTION_NAME (UtValidInternalObject);
381ae115bc7Smrj 
382ae115bc7Smrj 
383ae115bc7Smrj     /* Check for a null pointer */
384ae115bc7Smrj 
385ae115bc7Smrj     if (!Object)
386ae115bc7Smrj     {
387aa2aa9a6SDana Myers         ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "**** Null Object Ptr\n"));
388ae115bc7Smrj         return (FALSE);
389ae115bc7Smrj     }
390ae115bc7Smrj 
391ae115bc7Smrj     /* Check the descriptor type field */
392ae115bc7Smrj 
393ae115bc7Smrj     switch (ACPI_GET_DESCRIPTOR_TYPE (Object))
394ae115bc7Smrj     {
395ae115bc7Smrj     case ACPI_DESC_TYPE_OPERAND:
396ae115bc7Smrj 
397ae115bc7Smrj         /* The object appears to be a valid ACPI_OPERAND_OBJECT */
398ae115bc7Smrj 
399ae115bc7Smrj         return (TRUE);
400ae115bc7Smrj 
401ae115bc7Smrj     default:
402*cb565728SJerry Jelinek 
403aa2aa9a6SDana Myers         ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
404*cb565728SJerry Jelinek             "%p is not an ACPI operand obj [%s]\n",
405ae115bc7Smrj             Object, AcpiUtGetDescriptorName (Object)));
406ae115bc7Smrj         break;
407ae115bc7Smrj     }
408ae115bc7Smrj 
409ae115bc7Smrj     return (FALSE);
410ae115bc7Smrj }
411ae115bc7Smrj 
412ae115bc7Smrj 
413ae115bc7Smrj /*******************************************************************************
414ae115bc7Smrj  *
415ae115bc7Smrj  * FUNCTION:    AcpiUtAllocateObjectDescDbg
416ae115bc7Smrj  *
417ae115bc7Smrj  * PARAMETERS:  ModuleName          - Caller's module name (for error output)
418ae115bc7Smrj  *              LineNumber          - Caller's line number (for error output)
419ae115bc7Smrj  *              ComponentId         - Caller's component ID (for error output)
420ae115bc7Smrj  *
421ae115bc7Smrj  * RETURN:      Pointer to newly allocated object descriptor. Null on error
422ae115bc7Smrj  *
423ae115bc7Smrj  * DESCRIPTION: Allocate a new object descriptor. Gracefully handle
424ae115bc7Smrj  *              error conditions.
425ae115bc7Smrj  *
426ae115bc7Smrj  ******************************************************************************/
427ae115bc7Smrj 
428ae115bc7Smrj void *
AcpiUtAllocateObjectDescDbg(const char * ModuleName,UINT32 LineNumber,UINT32 ComponentId)429ae115bc7Smrj AcpiUtAllocateObjectDescDbg (
430db2bae30SDana Myers     const char              *ModuleName,
431ae115bc7Smrj     UINT32                  LineNumber,
432ae115bc7Smrj     UINT32                  ComponentId)
433ae115bc7Smrj {
434ae115bc7Smrj     ACPI_OPERAND_OBJECT     *Object;
435ae115bc7Smrj 
436ae115bc7Smrj 
437ae115bc7Smrj     ACPI_FUNCTION_TRACE (UtAllocateObjectDescDbg);
438ae115bc7Smrj 
439ae115bc7Smrj 
440ae115bc7Smrj     Object = AcpiOsAcquireObject (AcpiGbl_OperandCache);
441ae115bc7Smrj     if (!Object)
442ae115bc7Smrj     {
443ae115bc7Smrj         ACPI_ERROR ((ModuleName, LineNumber,
444ae115bc7Smrj             "Could not allocate an object descriptor"));
445ae115bc7Smrj 
446ae115bc7Smrj         return_PTR (NULL);
447ae115bc7Smrj     }
448ae115bc7Smrj 
449ae115bc7Smrj     /* Mark the descriptor type */
450ae115bc7Smrj 
451ae115bc7Smrj     ACPI_SET_DESCRIPTOR_TYPE (Object, ACPI_DESC_TYPE_OPERAND);
452ae115bc7Smrj 
453ae115bc7Smrj     ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "%p Size %X\n",
454ae115bc7Smrj         Object, (UINT32) sizeof (ACPI_OPERAND_OBJECT)));
455ae115bc7Smrj 
456ae115bc7Smrj     return_PTR (Object);
457ae115bc7Smrj }
458ae115bc7Smrj 
459ae115bc7Smrj 
460ae115bc7Smrj /*******************************************************************************
461ae115bc7Smrj  *
462ae115bc7Smrj  * FUNCTION:    AcpiUtDeleteObjectDesc
463ae115bc7Smrj  *
464ae115bc7Smrj  * PARAMETERS:  Object          - An Acpi internal object to be deleted
465ae115bc7Smrj  *
466ae115bc7Smrj  * RETURN:      None.
467ae115bc7Smrj  *
468ae115bc7Smrj  * DESCRIPTION: Free an ACPI object descriptor or add it to the object cache
469ae115bc7Smrj  *
470ae115bc7Smrj  ******************************************************************************/
471ae115bc7Smrj 
472ae115bc7Smrj void
AcpiUtDeleteObjectDesc(ACPI_OPERAND_OBJECT * Object)473ae115bc7Smrj AcpiUtDeleteObjectDesc (
474ae115bc7Smrj     ACPI_OPERAND_OBJECT     *Object)
475ae115bc7Smrj {
476ae115bc7Smrj     ACPI_FUNCTION_TRACE_PTR (UtDeleteObjectDesc, Object);
477ae115bc7Smrj 
478ae115bc7Smrj 
479*cb565728SJerry Jelinek     /* Object must be of type ACPI_OPERAND_OBJECT */
480ae115bc7Smrj 
481ae115bc7Smrj     if (ACPI_GET_DESCRIPTOR_TYPE (Object) != ACPI_DESC_TYPE_OPERAND)
482ae115bc7Smrj     {
483ae115bc7Smrj         ACPI_ERROR ((AE_INFO,
484ae115bc7Smrj             "%p is not an ACPI Operand object [%s]", Object,
485ae115bc7Smrj             AcpiUtGetDescriptorName (Object)));
486ae115bc7Smrj         return_VOID;
487ae115bc7Smrj     }
488ae115bc7Smrj 
489ae115bc7Smrj     (void) AcpiOsReleaseObject (AcpiGbl_OperandCache, Object);
490ae115bc7Smrj     return_VOID;
491ae115bc7Smrj }
492ae115bc7Smrj 
493ae115bc7Smrj 
494ae115bc7Smrj /*******************************************************************************
495ae115bc7Smrj  *
496ae115bc7Smrj  * FUNCTION:    AcpiUtGetSimpleObjectSize
497ae115bc7Smrj  *
498ae115bc7Smrj  * PARAMETERS:  InternalObject     - An ACPI operand object
499ae115bc7Smrj  *              ObjLength          - Where the length is returned
500ae115bc7Smrj  *
501ae115bc7Smrj  * RETURN:      Status
502ae115bc7Smrj  *
503ae115bc7Smrj  * DESCRIPTION: This function is called to determine the space required to
504ae115bc7Smrj  *              contain a simple object for return to an external user.
505ae115bc7Smrj  *
506ae115bc7Smrj  *              The length includes the object structure plus any additional
507ae115bc7Smrj  *              needed space.
508ae115bc7Smrj  *
509ae115bc7Smrj  ******************************************************************************/
510ae115bc7Smrj 
511ae115bc7Smrj static ACPI_STATUS
AcpiUtGetSimpleObjectSize(ACPI_OPERAND_OBJECT * InternalObject,ACPI_SIZE * ObjLength)512ae115bc7Smrj AcpiUtGetSimpleObjectSize (
513ae115bc7Smrj     ACPI_OPERAND_OBJECT     *InternalObject,
514ae115bc7Smrj     ACPI_SIZE               *ObjLength)
515ae115bc7Smrj {
516ae115bc7Smrj     ACPI_SIZE               Length;
517db2bae30SDana Myers     ACPI_SIZE               Size;
518ae115bc7Smrj     ACPI_STATUS             Status = AE_OK;
519ae115bc7Smrj 
520ae115bc7Smrj 
521ae115bc7Smrj     ACPI_FUNCTION_TRACE_PTR (UtGetSimpleObjectSize, InternalObject);
522ae115bc7Smrj 
523ae115bc7Smrj 
524db2bae30SDana Myers     /* Start with the length of the (external) Acpi object */
525ae115bc7Smrj 
526ae115bc7Smrj     Length = sizeof (ACPI_OBJECT);
527ae115bc7Smrj 
528db2bae30SDana Myers     /* A NULL object is allowed, can be a legal uninitialized package element */
529db2bae30SDana Myers 
530db2bae30SDana Myers     if (!InternalObject)
531db2bae30SDana Myers     {
532db2bae30SDana Myers         /*
533db2bae30SDana Myers          * Object is NULL, just return the length of ACPI_OBJECT
534db2bae30SDana Myers          * (A NULL ACPI_OBJECT is an object of all zeroes.)
535db2bae30SDana Myers          */
536db2bae30SDana Myers         *ObjLength = ACPI_ROUND_UP_TO_NATIVE_WORD (Length);
537db2bae30SDana Myers         return_ACPI_STATUS (AE_OK);
538db2bae30SDana Myers     }
539db2bae30SDana Myers 
540db2bae30SDana Myers     /* A Namespace Node should never appear here */
541db2bae30SDana Myers 
542ae115bc7Smrj     if (ACPI_GET_DESCRIPTOR_TYPE (InternalObject) == ACPI_DESC_TYPE_NAMED)
543ae115bc7Smrj     {
544db2bae30SDana Myers         /* A namespace node should never get here */
545ae115bc7Smrj 
546db2bae30SDana Myers         return_ACPI_STATUS (AE_AML_INTERNAL);
547ae115bc7Smrj     }
548ae115bc7Smrj 
549ae115bc7Smrj     /*
550ae115bc7Smrj      * The final length depends on the object type
551ae115bc7Smrj      * Strings and Buffers are packed right up against the parent object and
552ae115bc7Smrj      * must be accessed bytewise or there may be alignment problems on
553ae115bc7Smrj      * certain processors
554ae115bc7Smrj      */
555aa2aa9a6SDana Myers     switch (InternalObject->Common.Type)
556ae115bc7Smrj     {
557ae115bc7Smrj     case ACPI_TYPE_STRING:
558ae115bc7Smrj 
559ae115bc7Smrj         Length += (ACPI_SIZE) InternalObject->String.Length + 1;
560ae115bc7Smrj         break;
561ae115bc7Smrj 
562ae115bc7Smrj     case ACPI_TYPE_BUFFER:
563ae115bc7Smrj 
564ae115bc7Smrj         Length += (ACPI_SIZE) InternalObject->Buffer.Length;
565ae115bc7Smrj         break;
566ae115bc7Smrj 
567ae115bc7Smrj     case ACPI_TYPE_INTEGER:
568ae115bc7Smrj     case ACPI_TYPE_PROCESSOR:
569ae115bc7Smrj     case ACPI_TYPE_POWER:
570ae115bc7Smrj 
571db2bae30SDana Myers         /* No extra data for these types */
572db2bae30SDana Myers 
573ae115bc7Smrj         break;
574ae115bc7Smrj 
575ae115bc7Smrj     case ACPI_TYPE_LOCAL_REFERENCE:
576ae115bc7Smrj 
577db2bae30SDana Myers         switch (InternalObject->Reference.Class)
578ae115bc7Smrj         {
579db2bae30SDana Myers         case ACPI_REFCLASS_NAME:
580ae115bc7Smrj             /*
581ae115bc7Smrj              * Get the actual length of the full pathname to this object.
582ae115bc7Smrj              * The reference will be converted to the pathname to the object
583ae115bc7Smrj              */
584db2bae30SDana Myers             Size = AcpiNsGetPathnameLength (InternalObject->Reference.Node);
585db2bae30SDana Myers             if (!Size)
586db2bae30SDana Myers             {
587db2bae30SDana Myers                 return_ACPI_STATUS (AE_BAD_PARAMETER);
588db2bae30SDana Myers             }
589db2bae30SDana Myers 
590db2bae30SDana Myers             Length += ACPI_ROUND_UP_TO_NATIVE_WORD (Size);
591ae115bc7Smrj             break;
592ae115bc7Smrj 
593ae115bc7Smrj         default:
594ae115bc7Smrj             /*
595ae115bc7Smrj              * No other reference opcodes are supported.
596ae115bc7Smrj              * Notably, Locals and Args are not supported, but this may be
597ae115bc7Smrj              * required eventually.
598ae115bc7Smrj              */
599db2bae30SDana Myers             ACPI_ERROR ((AE_INFO, "Cannot convert to external object - "
60026f3cdf0SGordon Ross                 "unsupported Reference Class [%s] 0x%X in object %p",
601db2bae30SDana Myers                 AcpiUtGetReferenceName (InternalObject),
602db2bae30SDana Myers                 InternalObject->Reference.Class, InternalObject));
603ae115bc7Smrj             Status = AE_TYPE;
604ae115bc7Smrj             break;
605ae115bc7Smrj         }
606ae115bc7Smrj         break;
607ae115bc7Smrj 
608ae115bc7Smrj     default:
609ae115bc7Smrj 
610db2bae30SDana Myers         ACPI_ERROR ((AE_INFO, "Cannot convert to external object - "
61126f3cdf0SGordon Ross             "unsupported type [%s] 0x%X in object %p",
612db2bae30SDana Myers             AcpiUtGetObjectTypeName (InternalObject),
613aa2aa9a6SDana Myers             InternalObject->Common.Type, InternalObject));
614ae115bc7Smrj         Status = AE_TYPE;
615ae115bc7Smrj         break;
616ae115bc7Smrj     }
617ae115bc7Smrj 
618ae115bc7Smrj     /*
619ae115bc7Smrj      * Account for the space required by the object rounded up to the next
620ae115bc7Smrj      * multiple of the machine word size. This keeps each object aligned
621ae115bc7Smrj      * on a machine word boundary. (preventing alignment faults on some
622ae115bc7Smrj      * machines.)
623ae115bc7Smrj      */
624ae115bc7Smrj     *ObjLength = ACPI_ROUND_UP_TO_NATIVE_WORD (Length);
625ae115bc7Smrj     return_ACPI_STATUS (Status);
626ae115bc7Smrj }
627ae115bc7Smrj 
628ae115bc7Smrj 
629ae115bc7Smrj /*******************************************************************************
630ae115bc7Smrj  *
631ae115bc7Smrj  * FUNCTION:    AcpiUtGetElementLength
632ae115bc7Smrj  *
633ae115bc7Smrj  * PARAMETERS:  ACPI_PKG_CALLBACK
634ae115bc7Smrj  *
635ae115bc7Smrj  * RETURN:      Status
636ae115bc7Smrj  *
637ae115bc7Smrj  * DESCRIPTION: Get the length of one package element.
638ae115bc7Smrj  *
639ae115bc7Smrj  ******************************************************************************/
640ae115bc7Smrj 
641ae115bc7Smrj static ACPI_STATUS
AcpiUtGetElementLength(UINT8 ObjectType,ACPI_OPERAND_OBJECT * SourceObject,ACPI_GENERIC_STATE * State,void * Context)642ae115bc7Smrj AcpiUtGetElementLength (
643ae115bc7Smrj     UINT8                   ObjectType,
644ae115bc7Smrj     ACPI_OPERAND_OBJECT     *SourceObject,
645ae115bc7Smrj     ACPI_GENERIC_STATE      *State,
646ae115bc7Smrj     void                    *Context)
647ae115bc7Smrj {
648ae115bc7Smrj     ACPI_STATUS             Status = AE_OK;
649ae115bc7Smrj     ACPI_PKG_INFO           *Info = (ACPI_PKG_INFO *) Context;
650ae115bc7Smrj     ACPI_SIZE               ObjectSpace;
651ae115bc7Smrj 
652ae115bc7Smrj 
653ae115bc7Smrj     switch (ObjectType)
654ae115bc7Smrj     {
655ae115bc7Smrj     case ACPI_COPY_TYPE_SIMPLE:
656ae115bc7Smrj         /*
657ae115bc7Smrj          * Simple object - just get the size (Null object/entry is handled
658ae115bc7Smrj          * here also) and sum it into the running package length
659ae115bc7Smrj          */
660ae115bc7Smrj         Status = AcpiUtGetSimpleObjectSize (SourceObject, &ObjectSpace);
661ae115bc7Smrj         if (ACPI_FAILURE (Status))
662ae115bc7Smrj         {
663ae115bc7Smrj             return (Status);
664ae115bc7Smrj         }
665ae115bc7Smrj 
666ae115bc7Smrj         Info->Length += ObjectSpace;
667ae115bc7Smrj         break;
668ae115bc7Smrj 
669ae115bc7Smrj     case ACPI_COPY_TYPE_PACKAGE:
670ae115bc7Smrj 
671ae115bc7Smrj         /* Package object - nothing much to do here, let the walk handle it */
672ae115bc7Smrj 
673ae115bc7Smrj         Info->NumPackages++;
674ae115bc7Smrj         State->Pkg.ThisTargetObj = NULL;
675ae115bc7Smrj         break;
676ae115bc7Smrj 
677ae115bc7Smrj     default:
678ae115bc7Smrj 
679ae115bc7Smrj         /* No other types allowed */
680ae115bc7Smrj 
681ae115bc7Smrj         return (AE_BAD_PARAMETER);
682ae115bc7Smrj     }
683ae115bc7Smrj 
684ae115bc7Smrj     return (Status);
685ae115bc7Smrj }
686ae115bc7Smrj 
687ae115bc7Smrj 
688ae115bc7Smrj /*******************************************************************************
689ae115bc7Smrj  *
690ae115bc7Smrj  * FUNCTION:    AcpiUtGetPackageObjectSize
691ae115bc7Smrj  *
692ae115bc7Smrj  * PARAMETERS:  InternalObject      - An ACPI internal object
693ae115bc7Smrj  *              ObjLength           - Where the length is returned
694ae115bc7Smrj  *
695ae115bc7Smrj  * RETURN:      Status
696ae115bc7Smrj  *
697ae115bc7Smrj  * DESCRIPTION: This function is called to determine the space required to
698ae115bc7Smrj  *              contain a package object for return to an external user.
699ae115bc7Smrj  *
700ae115bc7Smrj  *              This is moderately complex since a package contains other
701ae115bc7Smrj  *              objects including packages.
702ae115bc7Smrj  *
703ae115bc7Smrj  ******************************************************************************/
704ae115bc7Smrj 
705ae115bc7Smrj static ACPI_STATUS
AcpiUtGetPackageObjectSize(ACPI_OPERAND_OBJECT * InternalObject,ACPI_SIZE * ObjLength)706ae115bc7Smrj AcpiUtGetPackageObjectSize (
707ae115bc7Smrj     ACPI_OPERAND_OBJECT     *InternalObject,
708ae115bc7Smrj     ACPI_SIZE               *ObjLength)
709ae115bc7Smrj {
710ae115bc7Smrj     ACPI_STATUS             Status;
711ae115bc7Smrj     ACPI_PKG_INFO           Info;
712ae115bc7Smrj 
713ae115bc7Smrj 
714ae115bc7Smrj     ACPI_FUNCTION_TRACE_PTR (UtGetPackageObjectSize, InternalObject);
715ae115bc7Smrj 
716ae115bc7Smrj 
717ae115bc7Smrj     Info.Length = 0;
718ae115bc7Smrj     Info.ObjectSpace = 0;
719ae115bc7Smrj     Info.NumPackages = 1;
720ae115bc7Smrj 
721*cb565728SJerry Jelinek     Status = AcpiUtWalkPackageTree (
722*cb565728SJerry Jelinek         InternalObject, NULL, AcpiUtGetElementLength, &Info);
723ae115bc7Smrj     if (ACPI_FAILURE (Status))
724ae115bc7Smrj     {
725ae115bc7Smrj         return_ACPI_STATUS (Status);
726ae115bc7Smrj     }
727ae115bc7Smrj 
728ae115bc7Smrj     /*
729ae115bc7Smrj      * We have handled all of the objects in all levels of the package.
730ae115bc7Smrj      * just add the length of the package objects themselves.
731ae115bc7Smrj      * Round up to the next machine word.
732ae115bc7Smrj      */
733*cb565728SJerry Jelinek     Info.Length += ACPI_ROUND_UP_TO_NATIVE_WORD (
734*cb565728SJerry Jelinek         sizeof (ACPI_OBJECT)) * (ACPI_SIZE) Info.NumPackages;
735ae115bc7Smrj 
736ae115bc7Smrj     /* Return the total package length */
737ae115bc7Smrj 
738ae115bc7Smrj     *ObjLength = Info.Length;
739ae115bc7Smrj     return_ACPI_STATUS (Status);
740ae115bc7Smrj }
741ae115bc7Smrj 
742ae115bc7Smrj 
743ae115bc7Smrj /*******************************************************************************
744ae115bc7Smrj  *
745ae115bc7Smrj  * FUNCTION:    AcpiUtGetObjectSize
746ae115bc7Smrj  *
747ae115bc7Smrj  * PARAMETERS:  InternalObject      - An ACPI internal object
748ae115bc7Smrj  *              ObjLength           - Where the length will be returned
749ae115bc7Smrj  *
750ae115bc7Smrj  * RETURN:      Status
751ae115bc7Smrj  *
752ae115bc7Smrj  * DESCRIPTION: This function is called to determine the space required to
753ae115bc7Smrj  *              contain an object for return to an API user.
754ae115bc7Smrj  *
755ae115bc7Smrj  ******************************************************************************/
756ae115bc7Smrj 
757ae115bc7Smrj ACPI_STATUS
AcpiUtGetObjectSize(ACPI_OPERAND_OBJECT * InternalObject,ACPI_SIZE * ObjLength)758ae115bc7Smrj AcpiUtGetObjectSize (
759ae115bc7Smrj     ACPI_OPERAND_OBJECT     *InternalObject,
760ae115bc7Smrj     ACPI_SIZE               *ObjLength)
761ae115bc7Smrj {
762ae115bc7Smrj     ACPI_STATUS             Status;
763ae115bc7Smrj 
764ae115bc7Smrj 
765ae115bc7Smrj     ACPI_FUNCTION_ENTRY ();
766ae115bc7Smrj 
767ae115bc7Smrj 
768*cb565728SJerry Jelinek     if ((ACPI_GET_DESCRIPTOR_TYPE (InternalObject) ==
769*cb565728SJerry Jelinek             ACPI_DESC_TYPE_OPERAND) &&
770aa2aa9a6SDana Myers         (InternalObject->Common.Type == ACPI_TYPE_PACKAGE))
771ae115bc7Smrj     {
772ae115bc7Smrj         Status = AcpiUtGetPackageObjectSize (InternalObject, ObjLength);
773ae115bc7Smrj     }
774ae115bc7Smrj     else
775ae115bc7Smrj     {
776ae115bc7Smrj         Status = AcpiUtGetSimpleObjectSize (InternalObject, ObjLength);
777ae115bc7Smrj     }
778ae115bc7Smrj 
779ae115bc7Smrj     return (Status);
780ae115bc7Smrj }
781