13446Smrj /******************************************************************************
23446Smrj  *
33446Smrj  * Module Name: utobject - ACPI object create/delete/size/cache routines
4*7851SDana.Myers@Sun.COM  *              $Revision: 1.108 $
53446Smrj  *
63446Smrj  *****************************************************************************/
73446Smrj 
83446Smrj /******************************************************************************
93446Smrj  *
103446Smrj  * 1. Copyright Notice
113446Smrj  *
12*7851SDana.Myers@Sun.COM  * Some or all of this work - Copyright (c) 1999 - 2008, Intel Corp.
133446Smrj  * All rights reserved.
143446Smrj  *
153446Smrj  * 2. License
163446Smrj  *
173446Smrj  * 2.1. This is your license from Intel Corp. under its intellectual property
183446Smrj  * rights.  You may have additional license terms from the party that provided
193446Smrj  * you this software, covering your right to use that party's intellectual
203446Smrj  * property rights.
213446Smrj  *
223446Smrj  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
233446Smrj  * copy of the source code appearing in this file ("Covered Code") an
243446Smrj  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
253446Smrj  * base code distributed originally by Intel ("Original Intel Code") to copy,
263446Smrj  * make derivatives, distribute, use and display any portion of the Covered
273446Smrj  * Code in any form, with the right to sublicense such rights; and
283446Smrj  *
293446Smrj  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
303446Smrj  * license (with the right to sublicense), under only those claims of Intel
313446Smrj  * patents that are infringed by the Original Intel Code, to make, use, sell,
323446Smrj  * offer to sell, and import the Covered Code and derivative works thereof
333446Smrj  * solely to the minimum extent necessary to exercise the above copyright
343446Smrj  * license, and in no event shall the patent license extend to any additions
353446Smrj  * to or modifications of the Original Intel Code.  No other license or right
363446Smrj  * is granted directly or by implication, estoppel or otherwise;
373446Smrj  *
383446Smrj  * The above copyright and patent license is granted only if the following
393446Smrj  * conditions are met:
403446Smrj  *
413446Smrj  * 3. Conditions
423446Smrj  *
433446Smrj  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
443446Smrj  * Redistribution of source code of any substantial portion of the Covered
453446Smrj  * Code or modification with rights to further distribute source must include
463446Smrj  * the above Copyright Notice, the above License, this list of Conditions,
473446Smrj  * and the following Disclaimer and Export Compliance provision.  In addition,
483446Smrj  * Licensee must cause all Covered Code to which Licensee contributes to
493446Smrj  * contain a file documenting the changes Licensee made to create that Covered
503446Smrj  * Code and the date of any change.  Licensee must include in that file the
513446Smrj  * documentation of any changes made by any predecessor Licensee.  Licensee
523446Smrj  * must include a prominent statement that the modification is derived,
533446Smrj  * directly or indirectly, from Original Intel Code.
543446Smrj  *
553446Smrj  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
563446Smrj  * Redistribution of source code of any substantial portion of the Covered
573446Smrj  * Code or modification without rights to further distribute source must
583446Smrj  * include the following Disclaimer and Export Compliance provision in the
593446Smrj  * documentation and/or other materials provided with distribution.  In
603446Smrj  * addition, Licensee may not authorize further sublicense of source of any
613446Smrj  * portion of the Covered Code, and must include terms to the effect that the
623446Smrj  * license from Licensee to its licensee is limited to the intellectual
633446Smrj  * property embodied in the software Licensee provides to its licensee, and
643446Smrj  * not to intellectual property embodied in modifications its licensee may
653446Smrj  * make.
663446Smrj  *
673446Smrj  * 3.3. Redistribution of Executable. Redistribution in executable form of any
683446Smrj  * substantial portion of the Covered Code or modification must reproduce the
693446Smrj  * above Copyright Notice, and the following Disclaimer and Export Compliance
703446Smrj  * provision in the documentation and/or other materials provided with the
713446Smrj  * distribution.
723446Smrj  *
733446Smrj  * 3.4. Intel retains all right, title, and interest in and to the Original
743446Smrj  * Intel Code.
753446Smrj  *
763446Smrj  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
773446Smrj  * Intel shall be used in advertising or otherwise to promote the sale, use or
783446Smrj  * other dealings in products derived from or relating to the Covered Code
793446Smrj  * without prior written authorization from Intel.
803446Smrj  *
813446Smrj  * 4. Disclaimer and Export Compliance
823446Smrj  *
833446Smrj  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
843446Smrj  * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
853446Smrj  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
863446Smrj  * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
873446Smrj  * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
883446Smrj  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
893446Smrj  * PARTICULAR PURPOSE.
903446Smrj  *
913446Smrj  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
923446Smrj  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
933446Smrj  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
943446Smrj  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
953446Smrj  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
963446Smrj  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
973446Smrj  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
983446Smrj  * LIMITED REMEDY.
993446Smrj  *
1003446Smrj  * 4.3. Licensee shall not export, either directly or indirectly, any of this
1013446Smrj  * software or system incorporating such software without first obtaining any
1023446Smrj  * required license or other approval from the U. S. Department of Commerce or
1033446Smrj  * any other agency or department of the United States Government.  In the
1043446Smrj  * event Licensee exports any such software from the United States or
1053446Smrj  * re-exports any such software from a foreign destination, Licensee shall
1063446Smrj  * ensure that the distribution and export/re-export of the software is in
1073446Smrj  * compliance with all laws, regulations, orders, or other restrictions of the
1083446Smrj  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
1093446Smrj  * any of its subsidiaries will export/re-export any technical data, process,
1103446Smrj  * software, or service, directly or indirectly, to any country for which the
1113446Smrj  * United States government or any agency thereof requires an export license,
1123446Smrj  * other governmental approval, or letter of assurance, without first obtaining
1133446Smrj  * such license, approval or letter.
1143446Smrj  *
1153446Smrj  *****************************************************************************/
1163446Smrj 
1173446Smrj #define __UTOBJECT_C__
1183446Smrj 
1193446Smrj #include "acpi.h"
1203446Smrj #include "acnamesp.h"
1213446Smrj 
1223446Smrj 
1233446Smrj #define _COMPONENT          ACPI_UTILITIES
1243446Smrj         ACPI_MODULE_NAME    ("utobject")
1253446Smrj 
1263446Smrj /* Local prototypes */
1273446Smrj 
1283446Smrj static ACPI_STATUS
1293446Smrj AcpiUtGetSimpleObjectSize (
1303446Smrj     ACPI_OPERAND_OBJECT     *Obj,
1313446Smrj     ACPI_SIZE               *ObjLength);
1323446Smrj 
1333446Smrj static ACPI_STATUS
1343446Smrj AcpiUtGetPackageObjectSize (
1353446Smrj     ACPI_OPERAND_OBJECT     *Obj,
1363446Smrj     ACPI_SIZE               *ObjLength);
1373446Smrj 
1383446Smrj static ACPI_STATUS
1393446Smrj AcpiUtGetElementLength (
1403446Smrj     UINT8                   ObjectType,
1413446Smrj     ACPI_OPERAND_OBJECT     *SourceObject,
1423446Smrj     ACPI_GENERIC_STATE      *State,
1433446Smrj     void                    *Context);
1443446Smrj 
1453446Smrj 
1463446Smrj /*******************************************************************************
1473446Smrj  *
1483446Smrj  * FUNCTION:    AcpiUtCreateInternalObjectDbg
1493446Smrj  *
1503446Smrj  * PARAMETERS:  ModuleName          - Source file name of caller
1513446Smrj  *              LineNumber          - Line number of caller
1523446Smrj  *              ComponentId         - Component type of caller
1533446Smrj  *              Type                - ACPI Type of the new object
1543446Smrj  *
1553446Smrj  * RETURN:      A new internal object, null on failure
1563446Smrj  *
1573446Smrj  * DESCRIPTION: Create and initialize a new internal object.
1583446Smrj  *
1593446Smrj  * NOTE:        We always allocate the worst-case object descriptor because
1603446Smrj  *              these objects are cached, and we want them to be
1613446Smrj  *              one-size-satisifies-any-request.  This in itself may not be
1623446Smrj  *              the most memory efficient, but the efficiency of the object
1633446Smrj  *              cache should more than make up for this!
1643446Smrj  *
1653446Smrj  ******************************************************************************/
1663446Smrj 
1673446Smrj ACPI_OPERAND_OBJECT  *
1683446Smrj AcpiUtCreateInternalObjectDbg (
169*7851SDana.Myers@Sun.COM     const char              *ModuleName,
1703446Smrj     UINT32                  LineNumber,
1713446Smrj     UINT32                  ComponentId,
1723446Smrj     ACPI_OBJECT_TYPE        Type)
1733446Smrj {
1743446Smrj     ACPI_OPERAND_OBJECT     *Object;
1753446Smrj     ACPI_OPERAND_OBJECT     *SecondObject;
1763446Smrj 
1773446Smrj 
1783446Smrj     ACPI_FUNCTION_TRACE_STR (UtCreateInternalObjectDbg,
1793446Smrj         AcpiUtGetTypeName (Type));
1803446Smrj 
1813446Smrj 
1823446Smrj     /* Allocate the raw object descriptor */
1833446Smrj 
1843446Smrj     Object = AcpiUtAllocateObjectDescDbg (ModuleName, LineNumber, ComponentId);
1853446Smrj     if (!Object)
1863446Smrj     {
1873446Smrj         return_PTR (NULL);
1883446Smrj     }
1893446Smrj 
1903446Smrj     switch (Type)
1913446Smrj     {
1923446Smrj     case ACPI_TYPE_REGION:
1933446Smrj     case ACPI_TYPE_BUFFER_FIELD:
194*7851SDana.Myers@Sun.COM     case ACPI_TYPE_LOCAL_BANK_FIELD:
1953446Smrj 
1963446Smrj         /* These types require a secondary object */
1973446Smrj 
1983446Smrj         SecondObject = AcpiUtAllocateObjectDescDbg (ModuleName,
1993446Smrj                             LineNumber, ComponentId);
2003446Smrj         if (!SecondObject)
2013446Smrj         {
2023446Smrj             AcpiUtDeleteObjectDesc (Object);
2033446Smrj             return_PTR (NULL);
2043446Smrj         }
2053446Smrj 
2063446Smrj         SecondObject->Common.Type = ACPI_TYPE_LOCAL_EXTRA;
2073446Smrj         SecondObject->Common.ReferenceCount = 1;
2083446Smrj 
2093446Smrj         /* Link the second object to the first */
2103446Smrj 
2113446Smrj         Object->Common.NextObject = SecondObject;
2123446Smrj         break;
2133446Smrj 
2143446Smrj     default:
2153446Smrj         /* All others have no secondary object */
2163446Smrj         break;
2173446Smrj     }
2183446Smrj 
2193446Smrj     /* Save the object type in the object descriptor */
2203446Smrj 
2213446Smrj     Object->Common.Type = (UINT8) Type;
2223446Smrj 
2233446Smrj     /* Init the reference count */
2243446Smrj 
2253446Smrj     Object->Common.ReferenceCount = 1;
2263446Smrj 
2273446Smrj     /* Any per-type initialization should go here */
2283446Smrj 
2293446Smrj     return_PTR (Object);
2303446Smrj }
2313446Smrj 
2323446Smrj 
2333446Smrj /*******************************************************************************
2343446Smrj  *
235*7851SDana.Myers@Sun.COM  * FUNCTION:    AcpiUtCreatePackageObject
236*7851SDana.Myers@Sun.COM  *
237*7851SDana.Myers@Sun.COM  * PARAMETERS:  Count               - Number of package elements
238*7851SDana.Myers@Sun.COM  *
239*7851SDana.Myers@Sun.COM  * RETURN:      Pointer to a new Package object, null on failure
240*7851SDana.Myers@Sun.COM  *
241*7851SDana.Myers@Sun.COM  * DESCRIPTION: Create a fully initialized package object
242*7851SDana.Myers@Sun.COM  *
243*7851SDana.Myers@Sun.COM  ******************************************************************************/
244*7851SDana.Myers@Sun.COM 
245*7851SDana.Myers@Sun.COM ACPI_OPERAND_OBJECT *
246*7851SDana.Myers@Sun.COM AcpiUtCreatePackageObject (
247*7851SDana.Myers@Sun.COM     UINT32                  Count)
248*7851SDana.Myers@Sun.COM {
249*7851SDana.Myers@Sun.COM     ACPI_OPERAND_OBJECT     *PackageDesc;
250*7851SDana.Myers@Sun.COM     ACPI_OPERAND_OBJECT     **PackageElements;
251*7851SDana.Myers@Sun.COM 
252*7851SDana.Myers@Sun.COM 
253*7851SDana.Myers@Sun.COM     ACPI_FUNCTION_TRACE_U32 (UtCreatePackageObject, Count);
254*7851SDana.Myers@Sun.COM 
255*7851SDana.Myers@Sun.COM 
256*7851SDana.Myers@Sun.COM     /* Create a new Package object */
257*7851SDana.Myers@Sun.COM 
258*7851SDana.Myers@Sun.COM     PackageDesc = AcpiUtCreateInternalObject (ACPI_TYPE_PACKAGE);
259*7851SDana.Myers@Sun.COM     if (!PackageDesc)
260*7851SDana.Myers@Sun.COM     {
261*7851SDana.Myers@Sun.COM         return_PTR (NULL);
262*7851SDana.Myers@Sun.COM     }
263*7851SDana.Myers@Sun.COM 
264*7851SDana.Myers@Sun.COM     /*
265*7851SDana.Myers@Sun.COM      * Create the element array. Count+1 allows the array to be null
266*7851SDana.Myers@Sun.COM      * terminated.
267*7851SDana.Myers@Sun.COM      */
268*7851SDana.Myers@Sun.COM     PackageElements = ACPI_ALLOCATE_ZEROED (
269*7851SDana.Myers@Sun.COM                         ((ACPI_SIZE) Count + 1) * sizeof (void *));
270*7851SDana.Myers@Sun.COM     if (!PackageElements)
271*7851SDana.Myers@Sun.COM     {
272*7851SDana.Myers@Sun.COM         ACPI_FREE (PackageDesc);
273*7851SDana.Myers@Sun.COM         return_PTR (NULL);
274*7851SDana.Myers@Sun.COM     }
275*7851SDana.Myers@Sun.COM 
276*7851SDana.Myers@Sun.COM     PackageDesc->Package.Count = Count;
277*7851SDana.Myers@Sun.COM     PackageDesc->Package.Elements = PackageElements;
278*7851SDana.Myers@Sun.COM     return_PTR (PackageDesc);
279*7851SDana.Myers@Sun.COM }
280*7851SDana.Myers@Sun.COM 
281*7851SDana.Myers@Sun.COM 
282*7851SDana.Myers@Sun.COM /*******************************************************************************
283*7851SDana.Myers@Sun.COM  *
2843446Smrj  * FUNCTION:    AcpiUtCreateBufferObject
2853446Smrj  *
2863446Smrj  * PARAMETERS:  BufferSize             - Size of buffer to be created
2873446Smrj  *
2883446Smrj  * RETURN:      Pointer to a new Buffer object, null on failure
2893446Smrj  *
2903446Smrj  * DESCRIPTION: Create a fully initialized buffer object
2913446Smrj  *
2923446Smrj  ******************************************************************************/
2933446Smrj 
2943446Smrj ACPI_OPERAND_OBJECT *
2953446Smrj AcpiUtCreateBufferObject (
2963446Smrj     ACPI_SIZE               BufferSize)
2973446Smrj {
2983446Smrj     ACPI_OPERAND_OBJECT     *BufferDesc;
2993446Smrj     UINT8                   *Buffer = NULL;
3003446Smrj 
3013446Smrj 
3023446Smrj     ACPI_FUNCTION_TRACE_U32 (UtCreateBufferObject, BufferSize);
3033446Smrj 
3043446Smrj 
3053446Smrj     /* Create a new Buffer object */
3063446Smrj 
3073446Smrj     BufferDesc = AcpiUtCreateInternalObject (ACPI_TYPE_BUFFER);
3083446Smrj     if (!BufferDesc)
3093446Smrj     {
3103446Smrj         return_PTR (NULL);
3113446Smrj     }
3123446Smrj 
3133446Smrj     /* Create an actual buffer only if size > 0 */
3143446Smrj 
3153446Smrj     if (BufferSize > 0)
3163446Smrj     {
3173446Smrj         /* Allocate the actual buffer */
3183446Smrj 
3193446Smrj         Buffer = ACPI_ALLOCATE_ZEROED (BufferSize);
3203446Smrj         if (!Buffer)
3213446Smrj         {
3223446Smrj             ACPI_ERROR ((AE_INFO, "Could not allocate size %X",
3233446Smrj                 (UINT32) BufferSize));
3243446Smrj             AcpiUtRemoveReference (BufferDesc);
3253446Smrj             return_PTR (NULL);
3263446Smrj         }
3273446Smrj     }
3283446Smrj 
3293446Smrj     /* Complete buffer object initialization */
3303446Smrj 
3313446Smrj     BufferDesc->Buffer.Flags |= AOPOBJ_DATA_VALID;
3323446Smrj     BufferDesc->Buffer.Pointer = Buffer;
3333446Smrj     BufferDesc->Buffer.Length = (UINT32) BufferSize;
3343446Smrj 
3353446Smrj     /* Return the new buffer descriptor */
3363446Smrj 
3373446Smrj     return_PTR (BufferDesc);
3383446Smrj }
3393446Smrj 
3403446Smrj 
3413446Smrj /*******************************************************************************
3423446Smrj  *
3433446Smrj  * FUNCTION:    AcpiUtCreateStringObject
3443446Smrj  *
3453446Smrj  * PARAMETERS:  StringSize          - Size of string to be created. Does not
3463446Smrj  *                                    include NULL terminator, this is added
3473446Smrj  *                                    automatically.
3483446Smrj  *
3493446Smrj  * RETURN:      Pointer to a new String object
3503446Smrj  *
3513446Smrj  * DESCRIPTION: Create a fully initialized string object
3523446Smrj  *
3533446Smrj  ******************************************************************************/
3543446Smrj 
3553446Smrj ACPI_OPERAND_OBJECT *
3563446Smrj AcpiUtCreateStringObject (
3573446Smrj     ACPI_SIZE               StringSize)
3583446Smrj {
3593446Smrj     ACPI_OPERAND_OBJECT     *StringDesc;
3603446Smrj     char                    *String;
3613446Smrj 
3623446Smrj 
3633446Smrj     ACPI_FUNCTION_TRACE_U32 (UtCreateStringObject, StringSize);
3643446Smrj 
3653446Smrj 
3663446Smrj     /* Create a new String object */
3673446Smrj 
3683446Smrj     StringDesc = AcpiUtCreateInternalObject (ACPI_TYPE_STRING);
3693446Smrj     if (!StringDesc)
3703446Smrj     {
3713446Smrj         return_PTR (NULL);
3723446Smrj     }
3733446Smrj 
3743446Smrj     /*
3753446Smrj      * Allocate the actual string buffer -- (Size + 1) for NULL terminator.
3763446Smrj      * NOTE: Zero-length strings are NULL terminated
3773446Smrj      */
3783446Smrj     String = ACPI_ALLOCATE_ZEROED (StringSize + 1);
3793446Smrj     if (!String)
3803446Smrj     {
3813446Smrj         ACPI_ERROR ((AE_INFO, "Could not allocate size %X",
3823446Smrj             (UINT32) StringSize));
3833446Smrj         AcpiUtRemoveReference (StringDesc);
3843446Smrj         return_PTR (NULL);
3853446Smrj     }
3863446Smrj 
3873446Smrj     /* Complete string object initialization */
3883446Smrj 
3893446Smrj     StringDesc->String.Pointer = String;
3903446Smrj     StringDesc->String.Length = (UINT32) StringSize;
3913446Smrj 
3923446Smrj     /* Return the new string descriptor */
3933446Smrj 
3943446Smrj     return_PTR (StringDesc);
3953446Smrj }
3963446Smrj 
3973446Smrj 
3983446Smrj /*******************************************************************************
3993446Smrj  *
4003446Smrj  * FUNCTION:    AcpiUtValidInternalObject
4013446Smrj  *
4023446Smrj  * PARAMETERS:  Object              - Object to be validated
4033446Smrj  *
4043446Smrj  * RETURN:      TRUE if object is valid, FALSE otherwise
4053446Smrj  *
4063446Smrj  * DESCRIPTION: Validate a pointer to be an ACPI_OPERAND_OBJECT
4073446Smrj  *
4083446Smrj  ******************************************************************************/
4093446Smrj 
4103446Smrj BOOLEAN
4113446Smrj AcpiUtValidInternalObject (
4123446Smrj     void                    *Object)
4133446Smrj {
4143446Smrj 
4153446Smrj     ACPI_FUNCTION_NAME (UtValidInternalObject);
4163446Smrj 
4173446Smrj 
4183446Smrj     /* Check for a null pointer */
4193446Smrj 
4203446Smrj     if (!Object)
4213446Smrj     {
4223446Smrj         ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "**** Null Object Ptr\n"));
4233446Smrj         return (FALSE);
4243446Smrj     }
4253446Smrj 
4263446Smrj     /* Check the descriptor type field */
4273446Smrj 
4283446Smrj     switch (ACPI_GET_DESCRIPTOR_TYPE (Object))
4293446Smrj     {
4303446Smrj     case ACPI_DESC_TYPE_OPERAND:
4313446Smrj 
4323446Smrj         /* The object appears to be a valid ACPI_OPERAND_OBJECT  */
4333446Smrj 
4343446Smrj         return (TRUE);
4353446Smrj 
4363446Smrj     default:
4373446Smrj         ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
4383446Smrj                 "%p is not not an ACPI operand obj [%s]\n",
4393446Smrj                 Object, AcpiUtGetDescriptorName (Object)));
4403446Smrj         break;
4413446Smrj     }
4423446Smrj 
4433446Smrj     return (FALSE);
4443446Smrj }
4453446Smrj 
4463446Smrj 
4473446Smrj /*******************************************************************************
4483446Smrj  *
4493446Smrj  * FUNCTION:    AcpiUtAllocateObjectDescDbg
4503446Smrj  *
4513446Smrj  * PARAMETERS:  ModuleName          - Caller's module name (for error output)
4523446Smrj  *              LineNumber          - Caller's line number (for error output)
4533446Smrj  *              ComponentId         - Caller's component ID (for error output)
4543446Smrj  *
4553446Smrj  * RETURN:      Pointer to newly allocated object descriptor.  Null on error
4563446Smrj  *
4573446Smrj  * DESCRIPTION: Allocate a new object descriptor.  Gracefully handle
4583446Smrj  *              error conditions.
4593446Smrj  *
4603446Smrj  ******************************************************************************/
4613446Smrj 
4623446Smrj void *
4633446Smrj AcpiUtAllocateObjectDescDbg (
464*7851SDana.Myers@Sun.COM     const char              *ModuleName,
4653446Smrj     UINT32                  LineNumber,
4663446Smrj     UINT32                  ComponentId)
4673446Smrj {
4683446Smrj     ACPI_OPERAND_OBJECT     *Object;
4693446Smrj 
4703446Smrj 
4713446Smrj     ACPI_FUNCTION_TRACE (UtAllocateObjectDescDbg);
4723446Smrj 
4733446Smrj 
4743446Smrj     Object = AcpiOsAcquireObject (AcpiGbl_OperandCache);
4753446Smrj     if (!Object)
4763446Smrj     {
4773446Smrj         ACPI_ERROR ((ModuleName, LineNumber,
4783446Smrj             "Could not allocate an object descriptor"));
4793446Smrj 
4803446Smrj         return_PTR (NULL);
4813446Smrj     }
4823446Smrj 
4833446Smrj     /* Mark the descriptor type */
4843446Smrj 
4853446Smrj     ACPI_SET_DESCRIPTOR_TYPE (Object, ACPI_DESC_TYPE_OPERAND);
4863446Smrj 
4873446Smrj     ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "%p Size %X\n",
4883446Smrj             Object, (UINT32) sizeof (ACPI_OPERAND_OBJECT)));
4893446Smrj 
4903446Smrj     return_PTR (Object);
4913446Smrj }
4923446Smrj 
4933446Smrj 
4943446Smrj /*******************************************************************************
4953446Smrj  *
4963446Smrj  * FUNCTION:    AcpiUtDeleteObjectDesc
4973446Smrj  *
4983446Smrj  * PARAMETERS:  Object          - An Acpi internal object to be deleted
4993446Smrj  *
5003446Smrj  * RETURN:      None.
5013446Smrj  *
5023446Smrj  * DESCRIPTION: Free an ACPI object descriptor or add it to the object cache
5033446Smrj  *
5043446Smrj  ******************************************************************************/
5053446Smrj 
5063446Smrj void
5073446Smrj AcpiUtDeleteObjectDesc (
5083446Smrj     ACPI_OPERAND_OBJECT     *Object)
5093446Smrj {
5103446Smrj     ACPI_FUNCTION_TRACE_PTR (UtDeleteObjectDesc, Object);
5113446Smrj 
5123446Smrj 
5133446Smrj     /* Object must be an ACPI_OPERAND_OBJECT  */
5143446Smrj 
5153446Smrj     if (ACPI_GET_DESCRIPTOR_TYPE (Object) != ACPI_DESC_TYPE_OPERAND)
5163446Smrj     {
5173446Smrj         ACPI_ERROR ((AE_INFO,
5183446Smrj             "%p is not an ACPI Operand object [%s]", Object,
5193446Smrj             AcpiUtGetDescriptorName (Object)));
5203446Smrj         return_VOID;
5213446Smrj     }
5223446Smrj 
5233446Smrj     (void) AcpiOsReleaseObject (AcpiGbl_OperandCache, Object);
5243446Smrj     return_VOID;
5253446Smrj }
5263446Smrj 
5273446Smrj 
5283446Smrj /*******************************************************************************
5293446Smrj  *
5303446Smrj  * FUNCTION:    AcpiUtGetSimpleObjectSize
5313446Smrj  *
5323446Smrj  * PARAMETERS:  InternalObject     - An ACPI operand object
5333446Smrj  *              ObjLength          - Where the length is returned
5343446Smrj  *
5353446Smrj  * RETURN:      Status
5363446Smrj  *
5373446Smrj  * DESCRIPTION: This function is called to determine the space required to
5383446Smrj  *              contain a simple object for return to an external user.
5393446Smrj  *
5403446Smrj  *              The length includes the object structure plus any additional
5413446Smrj  *              needed space.
5423446Smrj  *
5433446Smrj  ******************************************************************************/
5443446Smrj 
5453446Smrj static ACPI_STATUS
5463446Smrj AcpiUtGetSimpleObjectSize (
5473446Smrj     ACPI_OPERAND_OBJECT     *InternalObject,
5483446Smrj     ACPI_SIZE               *ObjLength)
5493446Smrj {
5503446Smrj     ACPI_SIZE               Length;
551*7851SDana.Myers@Sun.COM     ACPI_SIZE               Size;
5523446Smrj     ACPI_STATUS             Status = AE_OK;
5533446Smrj 
5543446Smrj 
5553446Smrj     ACPI_FUNCTION_TRACE_PTR (UtGetSimpleObjectSize, InternalObject);
5563446Smrj 
5573446Smrj 
558*7851SDana.Myers@Sun.COM     /* Start with the length of the (external) Acpi object */
559*7851SDana.Myers@Sun.COM 
560*7851SDana.Myers@Sun.COM     Length = sizeof (ACPI_OBJECT);
561*7851SDana.Myers@Sun.COM 
562*7851SDana.Myers@Sun.COM     /* A NULL object is allowed, can be a legal uninitialized package element */
563*7851SDana.Myers@Sun.COM 
5643446Smrj     if (!InternalObject)
5653446Smrj     {
566*7851SDana.Myers@Sun.COM         /*
567*7851SDana.Myers@Sun.COM          * Object is NULL, just return the length of ACPI_OBJECT
568*7851SDana.Myers@Sun.COM          * (A NULL ACPI_OBJECT is an object of all zeroes.)
569*7851SDana.Myers@Sun.COM          */
570*7851SDana.Myers@Sun.COM         *ObjLength = ACPI_ROUND_UP_TO_NATIVE_WORD (Length);
5713446Smrj         return_ACPI_STATUS (AE_OK);
5723446Smrj     }
5733446Smrj 
574*7851SDana.Myers@Sun.COM     /* A Namespace Node should never appear here */
5753446Smrj 
5763446Smrj     if (ACPI_GET_DESCRIPTOR_TYPE (InternalObject) == ACPI_DESC_TYPE_NAMED)
5773446Smrj     {
578*7851SDana.Myers@Sun.COM         /* A namespace node should never get here */
5793446Smrj 
580*7851SDana.Myers@Sun.COM         return_ACPI_STATUS (AE_AML_INTERNAL);
5813446Smrj     }
5823446Smrj 
5833446Smrj     /*
5843446Smrj      * The final length depends on the object type
5853446Smrj      * Strings and Buffers are packed right up against the parent object and
5863446Smrj      * must be accessed bytewise or there may be alignment problems on
5873446Smrj      * certain processors
5883446Smrj      */
5893446Smrj     switch (ACPI_GET_OBJECT_TYPE (InternalObject))
5903446Smrj     {
5913446Smrj     case ACPI_TYPE_STRING:
5923446Smrj 
5933446Smrj         Length += (ACPI_SIZE) InternalObject->String.Length + 1;
5943446Smrj         break;
5953446Smrj 
5963446Smrj 
5973446Smrj     case ACPI_TYPE_BUFFER:
5983446Smrj 
5993446Smrj         Length += (ACPI_SIZE) InternalObject->Buffer.Length;
6003446Smrj         break;
6013446Smrj 
6023446Smrj 
6033446Smrj     case ACPI_TYPE_INTEGER:
6043446Smrj     case ACPI_TYPE_PROCESSOR:
6053446Smrj     case ACPI_TYPE_POWER:
6063446Smrj 
607*7851SDana.Myers@Sun.COM         /* No extra data for these types */
608*7851SDana.Myers@Sun.COM 
6093446Smrj         break;
6103446Smrj 
6113446Smrj 
6123446Smrj     case ACPI_TYPE_LOCAL_REFERENCE:
6133446Smrj 
614*7851SDana.Myers@Sun.COM         switch (InternalObject->Reference.Class)
6153446Smrj         {
616*7851SDana.Myers@Sun.COM         case ACPI_REFCLASS_NAME:
6173446Smrj 
6183446Smrj             /*
6193446Smrj              * Get the actual length of the full pathname to this object.
6203446Smrj              * The reference will be converted to the pathname to the object
6213446Smrj              */
622*7851SDana.Myers@Sun.COM             Size = AcpiNsGetPathnameLength (InternalObject->Reference.Node);
623*7851SDana.Myers@Sun.COM             if (!Size)
624*7851SDana.Myers@Sun.COM             {
625*7851SDana.Myers@Sun.COM                 return_ACPI_STATUS (AE_BAD_PARAMETER);
626*7851SDana.Myers@Sun.COM             }
627*7851SDana.Myers@Sun.COM 
628*7851SDana.Myers@Sun.COM             Length += ACPI_ROUND_UP_TO_NATIVE_WORD (Size);
6293446Smrj             break;
6303446Smrj 
6313446Smrj         default:
6323446Smrj 
6333446Smrj             /*
6343446Smrj              * No other reference opcodes are supported.
6353446Smrj              * Notably, Locals and Args are not supported, but this may be
6363446Smrj              * required eventually.
6373446Smrj              */
638*7851SDana.Myers@Sun.COM             ACPI_ERROR ((AE_INFO, "Cannot convert to external object - "
639*7851SDana.Myers@Sun.COM                 "unsupported Reference Class [%s] %X in object %p",
640*7851SDana.Myers@Sun.COM                 AcpiUtGetReferenceName (InternalObject),
641*7851SDana.Myers@Sun.COM                 InternalObject->Reference.Class, InternalObject));
6423446Smrj             Status = AE_TYPE;
6433446Smrj             break;
6443446Smrj         }
6453446Smrj         break;
6463446Smrj 
6473446Smrj 
6483446Smrj     default:
6493446Smrj 
650*7851SDana.Myers@Sun.COM         ACPI_ERROR ((AE_INFO, "Cannot convert to external object - "
651*7851SDana.Myers@Sun.COM             "unsupported type [%s] %X in object %p",
652*7851SDana.Myers@Sun.COM             AcpiUtGetObjectTypeName (InternalObject),
6533446Smrj             ACPI_GET_OBJECT_TYPE (InternalObject), InternalObject));
6543446Smrj         Status = AE_TYPE;
6553446Smrj         break;
6563446Smrj     }
6573446Smrj 
6583446Smrj     /*
6593446Smrj      * Account for the space required by the object rounded up to the next
6603446Smrj      * multiple of the machine word size.  This keeps each object aligned
6613446Smrj      * on a machine word boundary. (preventing alignment faults on some
6623446Smrj      * machines.)
6633446Smrj      */
6643446Smrj     *ObjLength = ACPI_ROUND_UP_TO_NATIVE_WORD (Length);
6653446Smrj     return_ACPI_STATUS (Status);
6663446Smrj }
6673446Smrj 
6683446Smrj 
6693446Smrj /*******************************************************************************
6703446Smrj  *
6713446Smrj  * FUNCTION:    AcpiUtGetElementLength
6723446Smrj  *
6733446Smrj  * PARAMETERS:  ACPI_PKG_CALLBACK
6743446Smrj  *
6753446Smrj  * RETURN:      Status
6763446Smrj  *
6773446Smrj  * DESCRIPTION: Get the length of one package element.
6783446Smrj  *
6793446Smrj  ******************************************************************************/
6803446Smrj 
6813446Smrj static ACPI_STATUS
6823446Smrj AcpiUtGetElementLength (
6833446Smrj     UINT8                   ObjectType,
6843446Smrj     ACPI_OPERAND_OBJECT     *SourceObject,
6853446Smrj     ACPI_GENERIC_STATE      *State,
6863446Smrj     void                    *Context)
6873446Smrj {
6883446Smrj     ACPI_STATUS             Status = AE_OK;
6893446Smrj     ACPI_PKG_INFO           *Info = (ACPI_PKG_INFO *) Context;
6903446Smrj     ACPI_SIZE               ObjectSpace;
6913446Smrj 
6923446Smrj 
6933446Smrj     switch (ObjectType)
6943446Smrj     {
6953446Smrj     case ACPI_COPY_TYPE_SIMPLE:
6963446Smrj 
6973446Smrj         /*
6983446Smrj          * Simple object - just get the size (Null object/entry is handled
6993446Smrj          * here also) and sum it into the running package length
7003446Smrj          */
7013446Smrj         Status = AcpiUtGetSimpleObjectSize (SourceObject, &ObjectSpace);
7023446Smrj         if (ACPI_FAILURE (Status))
7033446Smrj         {
7043446Smrj             return (Status);
7053446Smrj         }
7063446Smrj 
7073446Smrj         Info->Length += ObjectSpace;
7083446Smrj         break;
7093446Smrj 
7103446Smrj 
7113446Smrj     case ACPI_COPY_TYPE_PACKAGE:
7123446Smrj 
7133446Smrj         /* Package object - nothing much to do here, let the walk handle it */
7143446Smrj 
7153446Smrj         Info->NumPackages++;
7163446Smrj         State->Pkg.ThisTargetObj = NULL;
7173446Smrj         break;
7183446Smrj 
7193446Smrj 
7203446Smrj     default:
7213446Smrj 
7223446Smrj         /* No other types allowed */
7233446Smrj 
7243446Smrj         return (AE_BAD_PARAMETER);
7253446Smrj     }
7263446Smrj 
7273446Smrj     return (Status);
7283446Smrj }
7293446Smrj 
7303446Smrj 
7313446Smrj /*******************************************************************************
7323446Smrj  *
7333446Smrj  * FUNCTION:    AcpiUtGetPackageObjectSize
7343446Smrj  *
7353446Smrj  * PARAMETERS:  InternalObject      - An ACPI internal object
7363446Smrj  *              ObjLength           - Where the length is returned
7373446Smrj  *
7383446Smrj  * RETURN:      Status
7393446Smrj  *
7403446Smrj  * DESCRIPTION: This function is called to determine the space required to
7413446Smrj  *              contain a package object for return to an external user.
7423446Smrj  *
7433446Smrj  *              This is moderately complex since a package contains other
7443446Smrj  *              objects including packages.
7453446Smrj  *
7463446Smrj  ******************************************************************************/
7473446Smrj 
7483446Smrj static ACPI_STATUS
7493446Smrj AcpiUtGetPackageObjectSize (
7503446Smrj     ACPI_OPERAND_OBJECT     *InternalObject,
7513446Smrj     ACPI_SIZE               *ObjLength)
7523446Smrj {
7533446Smrj     ACPI_STATUS             Status;
7543446Smrj     ACPI_PKG_INFO           Info;
7553446Smrj 
7563446Smrj 
7573446Smrj     ACPI_FUNCTION_TRACE_PTR (UtGetPackageObjectSize, InternalObject);
7583446Smrj 
7593446Smrj 
7603446Smrj     Info.Length      = 0;
7613446Smrj     Info.ObjectSpace = 0;
7623446Smrj     Info.NumPackages = 1;
7633446Smrj 
7643446Smrj     Status = AcpiUtWalkPackageTree (InternalObject, NULL,
7653446Smrj                             AcpiUtGetElementLength, &Info);
7663446Smrj     if (ACPI_FAILURE (Status))
7673446Smrj     {
7683446Smrj         return_ACPI_STATUS (Status);
7693446Smrj     }
7703446Smrj 
7713446Smrj     /*
7723446Smrj      * We have handled all of the objects in all levels of the package.
7733446Smrj      * just add the length of the package objects themselves.
7743446Smrj      * Round up to the next machine word.
7753446Smrj      */
7763446Smrj     Info.Length += ACPI_ROUND_UP_TO_NATIVE_WORD (sizeof (ACPI_OBJECT)) *
7773446Smrj                     (ACPI_SIZE) Info.NumPackages;
7783446Smrj 
7793446Smrj     /* Return the total package length */
7803446Smrj 
7813446Smrj     *ObjLength = Info.Length;
7823446Smrj     return_ACPI_STATUS (Status);
7833446Smrj }
7843446Smrj 
7853446Smrj 
7863446Smrj /*******************************************************************************
7873446Smrj  *
7883446Smrj  * FUNCTION:    AcpiUtGetObjectSize
7893446Smrj  *
7903446Smrj  * PARAMETERS:  InternalObject      - An ACPI internal object
7913446Smrj  *              ObjLength           - Where the length will be returned
7923446Smrj  *
7933446Smrj  * RETURN:      Status
7943446Smrj  *
7953446Smrj  * DESCRIPTION: This function is called to determine the space required to
7963446Smrj  *              contain an object for return to an API user.
7973446Smrj  *
7983446Smrj  ******************************************************************************/
7993446Smrj 
8003446Smrj ACPI_STATUS
8013446Smrj AcpiUtGetObjectSize (
8023446Smrj     ACPI_OPERAND_OBJECT     *InternalObject,
8033446Smrj     ACPI_SIZE               *ObjLength)
8043446Smrj {
8053446Smrj     ACPI_STATUS             Status;
8063446Smrj 
8073446Smrj 
8083446Smrj     ACPI_FUNCTION_ENTRY ();
8093446Smrj 
8103446Smrj 
8113446Smrj     if ((ACPI_GET_DESCRIPTOR_TYPE (InternalObject) == ACPI_DESC_TYPE_OPERAND) &&
8123446Smrj         (ACPI_GET_OBJECT_TYPE (InternalObject) == ACPI_TYPE_PACKAGE))
8133446Smrj     {
8143446Smrj         Status = AcpiUtGetPackageObjectSize (InternalObject, ObjLength);
8153446Smrj     }
8163446Smrj     else
8173446Smrj     {
8183446Smrj         Status = AcpiUtGetSimpleObjectSize (InternalObject, ObjLength);
8193446Smrj     }
8203446Smrj 
8213446Smrj     return (Status);
8223446Smrj }
8233446Smrj 
8243446Smrj 
825